2011-10-31 17:55:06 +00:00
|
|
|
|
#pragma once
|
2010-03-18 19:32:14 +00:00
|
|
|
|
|
|
|
|
|
#include <map>
|
2012-09-05 19:51:09 +00:00
|
|
|
|
#include <list>
|
2010-03-18 19:32:14 +00:00
|
|
|
|
#include <string>
|
2014-07-09 13:39:19 +00:00
|
|
|
|
#include <set>
|
2010-03-18 19:32:14 +00:00
|
|
|
|
|
|
|
|
|
#include <DB/DataTypes/IDataType.h>
|
2016-02-16 16:39:39 +00:00
|
|
|
|
#include <DB/Core/Names.h>
|
2010-03-18 19:32:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2014-07-09 10:46:26 +00:00
|
|
|
|
struct NameAndTypePair
|
|
|
|
|
{
|
|
|
|
|
String name;
|
|
|
|
|
DataTypePtr type;
|
|
|
|
|
|
2014-07-09 11:45:51 +00:00
|
|
|
|
NameAndTypePair() {}
|
|
|
|
|
NameAndTypePair(const String & name_, const DataTypePtr & type_) : name(name_), type(type_) {}
|
|
|
|
|
|
2014-07-09 10:46:26 +00:00
|
|
|
|
bool operator<(const NameAndTypePair & rhs) const
|
|
|
|
|
{
|
2014-07-11 13:13:03 +00:00
|
|
|
|
return std::forward_as_tuple(name, type->getName()) < std::forward_as_tuple(rhs.name, rhs.type->getName());
|
2014-07-09 10:46:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(const NameAndTypePair & rhs) const
|
|
|
|
|
{
|
|
|
|
|
return name == rhs.name && type->getName() == rhs.type->getName();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
using NamesAndTypes = std::vector<NameAndTypePair>;
|
2011-11-01 17:12:11 +00:00
|
|
|
|
|
2014-07-09 13:39:19 +00:00
|
|
|
|
class NamesAndTypesList : public std::list<NameAndTypePair>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using std::list<NameAndTypePair>::list;
|
|
|
|
|
|
2015-05-28 03:49:28 +00:00
|
|
|
|
void readText(ReadBuffer & buf);
|
2015-02-15 13:30:07 +00:00
|
|
|
|
void writeText(WriteBuffer & buf) const;
|
2014-07-09 13:39:19 +00:00
|
|
|
|
|
2015-02-15 13:30:07 +00:00
|
|
|
|
String toString() const;
|
2015-05-28 03:49:28 +00:00
|
|
|
|
static NamesAndTypesList parse(const String & s);
|
2014-07-10 08:40:59 +00:00
|
|
|
|
|
2014-07-09 13:39:19 +00:00
|
|
|
|
/// Все элементы rhs должны быть различны.
|
2015-02-15 13:30:07 +00:00
|
|
|
|
bool isSubsetOf(const NamesAndTypesList & rhs) const;
|
2014-07-10 08:40:59 +00:00
|
|
|
|
|
|
|
|
|
/// Расстояние Хемминга между множествами
|
|
|
|
|
/// (иными словами, добавленные и удаленные столбцы считаются один раз; столбцы, изменившие тип, - дважды).
|
2015-02-15 13:30:07 +00:00
|
|
|
|
size_t sizeOfDifference(const NamesAndTypesList & rhs) const;
|
2014-07-14 14:07:47 +00:00
|
|
|
|
|
2015-02-15 13:30:07 +00:00
|
|
|
|
Names getNames() const;
|
2014-07-14 14:07:47 +00:00
|
|
|
|
|
|
|
|
|
/// Оставить только столбцы, имена которых есть в names. В names могут быть лишние столбцы.
|
2015-02-15 13:30:07 +00:00
|
|
|
|
NamesAndTypesList filter(const NameSet & names) const;
|
2014-07-15 09:56:17 +00:00
|
|
|
|
|
|
|
|
|
/// Оставить только столбцы, имена которых есть в names. В names могут быть лишние столбцы.
|
2015-02-15 13:30:07 +00:00
|
|
|
|
NamesAndTypesList filter(const Names & names) const;
|
2014-07-17 13:41:47 +00:00
|
|
|
|
|
|
|
|
|
/// В отличие от filter, возвращает столбцы в том порядке, в котором они идут в names.
|
2015-02-15 13:30:07 +00:00
|
|
|
|
NamesAndTypesList addTypes(const Names & names) const;
|
2014-07-09 13:39:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-05-28 08:11:52 +00:00
|
|
|
|
using NamesAndTypesListPtr = std::shared_ptr<NamesAndTypesList>;
|
2014-07-09 13:39:19 +00:00
|
|
|
|
|
2010-03-18 19:32:14 +00:00
|
|
|
|
}
|