2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/queryToString.h>
|
|
|
|
#include <Storages/ColumnDefault.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
ColumnDefaultType columnDefaultTypeFromString(const std::string & str)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static const std::unordered_map<std::string, ColumnDefaultType> map{
|
|
|
|
{ "DEFAULT", ColumnDefaultType::Default },
|
|
|
|
{ "MATERIALIZED", ColumnDefaultType::Materialized },
|
|
|
|
{ "ALIAS", ColumnDefaultType::Alias }
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto it = map.find(str);
|
|
|
|
return it != std::end(map) ? it->second : throw Exception{"Unknown column default specifier: " + str};
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string toString(const ColumnDefaultType type)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static const std::unordered_map<ColumnDefaultType, std::string> map{
|
|
|
|
{ ColumnDefaultType::Default, "DEFAULT" },
|
|
|
|
{ ColumnDefaultType::Materialized, "MATERIALIZED" },
|
|
|
|
{ ColumnDefaultType::Alias, "ALIAS" }
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto it = map.find(type);
|
|
|
|
return it != std::end(map) ? it->second : throw Exception{"Invalid ColumnDefaultType"};
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const ColumnDefault & lhs, const ColumnDefault & rhs)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return lhs.type == rhs.type && queryToString(lhs.expression) == queryToString(rhs.expression);
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|