ClickHouse/dbms/src/Core/NamesAndTypes.h

69 lines
1.9 KiB
C++
Raw Normal View History

2011-10-31 17:55:06 +00:00
#pragma once
2010-03-18 19:32:14 +00:00
#include <string>
#include <vector>
#include <initializer_list>
2010-03-18 19:32:14 +00:00
#include <DataTypes/IDataType.h>
#include <Core/Names.h>
2010-03-18 19:32:14 +00:00
namespace DB
{
struct NameAndType
{
String name;
DataTypePtr type;
NameAndType() {}
NameAndType(const String & name_, const DataTypePtr & type_) : name(name_), type(type_) {}
bool operator<(const NameAndType & rhs) const
{
return std::forward_as_tuple(name, type->getName()) < std::forward_as_tuple(rhs.name, rhs.type->getName());
}
bool operator==(const NameAndType & rhs) const
{
return name == rhs.name && type->equals(*rhs.type);
}
};
class NamesAndTypes : public std::vector<NameAndType>
2014-07-09 13:39:19 +00:00
{
public:
NamesAndTypes() {}
NamesAndTypes(std::initializer_list<NameAndType> init) : std::vector<NameAndType>(init) {}
template <typename Iterator>
NamesAndTypes(Iterator begin, Iterator end) : std::vector<NameAndType>(begin, end) {}
void readText(ReadBuffer & buf);
void writeText(WriteBuffer & buf) const;
2014-07-09 13:39:19 +00:00
String toString() const;
static NamesAndTypes parse(const String & s);
2014-07-10 08:40:59 +00:00
2017-04-30 13:50:16 +00:00
/// All `rhs` elements must be different.
bool isSubsetOf(const NamesAndTypes & rhs) const;
2014-07-10 08:40:59 +00:00
2017-04-30 13:50:16 +00:00
/// Hamming distance between sets
/// (in other words, the added and deleted columns are counted once, the columns that changed the type - twice).
size_t sizeOfDifference(const NamesAndTypes & rhs) const;
2014-07-14 14:07:47 +00:00
Names getNames() const;
2014-07-14 14:07:47 +00:00
2017-04-30 13:50:16 +00:00
/// Leave only the columns whose names are in the `names`. In `names` there can be superfluous columns.
NamesAndTypes filter(const NameSet & names) const;
2014-07-15 09:56:17 +00:00
2017-04-30 13:50:16 +00:00
/// Leave only the columns whose names are in the `names`. In `names` there can be superfluous columns.
NamesAndTypes filter(const Names & names) const;
2014-07-17 13:41:47 +00:00
2017-04-30 13:50:16 +00:00
/// Unlike `filter`, returns columns in the order in which they go in `names`.
NamesAndTypes addTypes(const Names & names) const;
2014-07-09 13:39:19 +00:00
};
2010-03-18 19:32:14 +00:00
}