2018-11-14 15:23:00 +00:00
|
|
|
#include <Storages/ColumnDefault.h>
|
|
|
|
#include <Parsers/queryToString.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2018-11-15 15:03:13 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
struct AliasNames
|
2016-12-12 07:24:56 +00:00
|
|
|
{
|
2018-11-15 15:03:13 +00:00
|
|
|
static constexpr const char * DEFAULT = "DEFAULT";
|
|
|
|
static constexpr const char * MATERIALIZED = "MATERIALIZED";
|
|
|
|
static constexpr const char * ALIAS = "ALIAS";
|
2022-02-07 23:21:10 +00:00
|
|
|
static constexpr const char * EPHEMERAL = "EPHEMERAL";
|
2018-11-15 15:03:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2018-11-15 15:03:13 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2018-11-22 21:19:58 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2018-03-12 13:47:01 +00:00
|
|
|
ColumnDefaultKind columnDefaultKindFromString(const std::string & str)
|
2016-12-12 07:24:56 +00:00
|
|
|
{
|
2018-03-12 13:47:01 +00:00
|
|
|
static const std::unordered_map<std::string, ColumnDefaultKind> map{
|
2018-11-15 15:03:13 +00:00
|
|
|
{ AliasNames::DEFAULT, ColumnDefaultKind::Default },
|
|
|
|
{ AliasNames::MATERIALIZED, ColumnDefaultKind::Materialized },
|
2022-02-07 23:21:10 +00:00
|
|
|
{ AliasNames::ALIAS, ColumnDefaultKind::Alias },
|
|
|
|
{ AliasNames::EPHEMERAL, ColumnDefaultKind::Ephemeral }
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto it = map.find(str);
|
2019-05-31 08:55:01 +00:00
|
|
|
if (it != std::end(map))
|
|
|
|
return it->second;
|
|
|
|
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown column default specifier: {}", str);
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-12 13:47:01 +00:00
|
|
|
std::string toString(const ColumnDefaultKind kind)
|
2016-12-12 07:24:56 +00:00
|
|
|
{
|
2018-03-12 13:47:01 +00:00
|
|
|
static const std::unordered_map<ColumnDefaultKind, std::string> map{
|
2018-11-15 15:03:13 +00:00
|
|
|
{ ColumnDefaultKind::Default, AliasNames::DEFAULT },
|
|
|
|
{ ColumnDefaultKind::Materialized, AliasNames::MATERIALIZED },
|
2022-02-07 23:21:10 +00:00
|
|
|
{ ColumnDefaultKind::Alias, AliasNames::ALIAS },
|
|
|
|
{ ColumnDefaultKind::Ephemeral, AliasNames::EPHEMERAL }
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
2018-03-12 13:47:01 +00:00
|
|
|
const auto it = map.find(kind);
|
2019-05-31 08:55:01 +00:00
|
|
|
if (it != std::end(map))
|
|
|
|
return it->second;
|
|
|
|
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Invalid ColumnDefaultKind");
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const ColumnDefault & lhs, const ColumnDefault & rhs)
|
|
|
|
{
|
2019-03-14 15:20:51 +00:00
|
|
|
auto expression_str = [](const ASTPtr & expr) { return expr ? queryToString(expr) : String(); };
|
|
|
|
return lhs.kind == rhs.kind && expression_str(lhs.expression) == expression_str(rhs.expression);
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|