ClickHouse/dbms/include/DB/Core/NamesAndTypes.h
2016-05-28 11:11:52 +03:00

69 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <map>
#include <list>
#include <string>
#include <set>
#include <DB/DataTypes/IDataType.h>
#include <DB/Core/Names.h>
namespace DB
{
struct NameAndTypePair
{
String name;
DataTypePtr type;
NameAndTypePair() {}
NameAndTypePair(const String & name_, const DataTypePtr & type_) : name(name_), type(type_) {}
bool operator<(const NameAndTypePair & rhs) const
{
return std::forward_as_tuple(name, type->getName()) < std::forward_as_tuple(rhs.name, rhs.type->getName());
}
bool operator==(const NameAndTypePair & rhs) const
{
return name == rhs.name && type->getName() == rhs.type->getName();
}
};
using NamesAndTypes = std::vector<NameAndTypePair>;
class NamesAndTypesList : public std::list<NameAndTypePair>
{
public:
using std::list<NameAndTypePair>::list;
void readText(ReadBuffer & buf);
void writeText(WriteBuffer & buf) const;
String toString() const;
static NamesAndTypesList parse(const String & s);
/// Все элементы rhs должны быть различны.
bool isSubsetOf(const NamesAndTypesList & rhs) const;
/// Расстояние Хемминга между множествами
/// (иными словами, добавленные и удаленные столбцы считаются один раз; столбцы, изменившие тип, - дважды).
size_t sizeOfDifference(const NamesAndTypesList & rhs) const;
Names getNames() const;
/// Оставить только столбцы, имена которых есть в names. В names могут быть лишние столбцы.
NamesAndTypesList filter(const NameSet & names) const;
/// Оставить только столбцы, имена которых есть в names. В names могут быть лишние столбцы.
NamesAndTypesList filter(const Names & names) const;
/// В отличие от filter, возвращает столбцы в том порядке, в котором они идут в names.
NamesAndTypesList addTypes(const Names & names) const;
};
using NamesAndTypesListPtr = std::shared_ptr<NamesAndTypesList>;
}