1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <Storages/ColumnDefault.h>
#include <Parsers/queryToString.h>
namespace
{
struct AliasNames
{
static constexpr const char * DEFAULT = "DEFAULT";
static constexpr const char * MATERIALIZED = "MATERIALIZED";
static constexpr const char * ALIAS = "ALIAS";
static constexpr const char * EPHEMERAL = "EPHEMERAL";
};
}
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
ColumnDefaultKind columnDefaultKindFromString(const std::string & str)
{
static const std::unordered_map<std::string, ColumnDefaultKind> map{
{ AliasNames::DEFAULT, ColumnDefaultKind::Default },
{ AliasNames::MATERIALIZED, ColumnDefaultKind::Materialized },
{ AliasNames::ALIAS, ColumnDefaultKind::Alias },
{ AliasNames::EPHEMERAL, ColumnDefaultKind::Ephemeral }
};
const auto it = map.find(str);
if (it != std::end(map))
return it->second;
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown column default specifier: {}", str);
}
std::string toString(const ColumnDefaultKind kind)
{
static const std::unordered_map<ColumnDefaultKind, std::string> map{
{ ColumnDefaultKind::Default, AliasNames::DEFAULT },
{ ColumnDefaultKind::Materialized, AliasNames::MATERIALIZED },
{ ColumnDefaultKind::Alias, AliasNames::ALIAS },
{ ColumnDefaultKind::Ephemeral, AliasNames::EPHEMERAL }
};
const auto it = map.find(kind);
if (it != std::end(map))
return it->second;
throw Exception(ErrorCodes::LOGICAL_ERROR, "Invalid ColumnDefaultKind");
}
bool operator==(const ColumnDefault & lhs, const ColumnDefault & rhs)
{
auto expression_str = [](const ASTPtr & expr) { return expr ? queryToString(expr) : String(); };
return lhs.kind == rhs.kind && expression_str(lhs.expression) == expression_str(rhs.expression);
}
}
|