ClickHouse/dbms/src/Parsers/ASTColumnDeclaration.h

88 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/IAST.h>
namespace DB
{
/** Name, type, default-specifier, default-expression, comment-expression.
* The type is optional if default-expression is specified.
*/
class ASTColumnDeclaration : public IAST
{
public:
String name;
ASTPtr type;
String default_specifier;
ASTPtr default_expression;
2018-10-11 02:57:48 +00:00
ASTPtr codec;
2018-11-08 12:03:42 +00:00
ASTPtr comment;
String getID(char delim) const override { return "ColumnDeclaration" + (delim + name); }
ASTPtr clone() const override
{
const auto res = std::make_shared<ASTColumnDeclaration>(*this);
res->children.clear();
if (type)
{
res->type = type;
res->children.push_back(res->type);
}
2018-01-10 00:04:08 +00:00
if (default_expression)
{
res->default_expression = default_expression->clone();
res->children.push_back(res->default_expression);
}
2018-10-11 02:57:48 +00:00
if (codec)
{
2018-12-14 13:28:34 +00:00
res->codec = codec->clone();
2018-10-11 02:57:48 +00:00
res->children.push_back(res->codec);
}
2018-11-08 12:03:42 +00:00
if (comment)
{
res->comment = comment->clone();
res->children.push_back(res->comment);
}
return res;
}
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
frame.need_parens = false;
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
settings.ostr << settings.nl_or_ws << indent_str << backQuoteIfNeed(name);
if (type)
{
settings.ostr << ' ';
type->formatImpl(settings, state, frame);
}
if (default_expression)
{
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << default_specifier << (settings.hilite ? hilite_none : "") << ' ';
default_expression->formatImpl(settings, state, frame);
}
2018-10-01 20:16:50 +00:00
2018-11-08 12:03:42 +00:00
if (comment)
2018-10-27 20:39:59 +00:00
{
2018-11-12 15:45:35 +00:00
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "COMMENT" << (settings.hilite ? hilite_none : "") << ' ';
2018-11-08 12:03:42 +00:00
comment->formatImpl(settings, state, frame);
2018-10-01 20:16:50 +00:00
}
2019-03-15 14:59:03 +00:00
if (codec)
{
settings.ostr << ' ';
codec->formatImpl(settings, state, frame);
}
}
};
}