1#include <Parsers/ASTColumnDeclaration.h>
2#include <Common/quoteString.h>
3
4
5namespace DB
6{
7
8ASTPtr ASTColumnDeclaration::clone() const
9{
10 const auto res = std::make_shared<ASTColumnDeclaration>(*this);
11 res->children.clear();
12
13 if (type)
14 {
15 res->type = type;
16 res->children.push_back(res->type);
17 }
18
19 if (default_expression)
20 {
21 res->default_expression = default_expression->clone();
22 res->children.push_back(res->default_expression);
23 }
24
25 if (comment)
26 {
27 res->comment = comment->clone();
28 res->children.push_back(res->comment);
29 }
30
31 if (codec)
32 {
33 res->codec = codec->clone();
34 res->children.push_back(res->codec);
35 }
36
37 if (ttl)
38 {
39 res->ttl = ttl->clone();
40 res->children.push_back(res->ttl);
41 }
42
43 return res;
44}
45
46void ASTColumnDeclaration::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
47{
48 frame.need_parens = false;
49
50 if (!settings.one_line)
51 settings.ostr << settings.nl_or_ws << std::string(4 * frame.indent, ' ');
52
53 /// We have to always backquote column names to avoid ambiguouty with INDEX and other declarations in CREATE query.
54 settings.ostr << backQuote(name);
55
56 if (type)
57 {
58 settings.ostr << ' ';
59 type->formatImpl(settings, state, frame);
60 }
61
62 if (default_expression)
63 {
64 settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << default_specifier << (settings.hilite ? hilite_none : "") << ' ';
65 default_expression->formatImpl(settings, state, frame);
66 }
67
68 if (comment)
69 {
70 settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "COMMENT" << (settings.hilite ? hilite_none : "") << ' ';
71 comment->formatImpl(settings, state, frame);
72 }
73
74 if (codec)
75 {
76 settings.ostr << ' ';
77 codec->formatImpl(settings, state, frame);
78 }
79
80 if (ttl)
81 {
82 settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "TTL" << (settings.hilite ? hilite_none : "") << ' ';
83 ttl->formatImpl(settings, state, frame);
84 }
85}
86
87}
88