2014-09-24 14:44:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Name, type, default-specifier, default-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;
|
|
|
|
|
|
|
|
ASTColumnDeclaration() = default;
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTColumnDeclaration(const StringRange range) : IAST{range} {}
|
2014-09-24 14:44:57 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
String getID() const override { return "ColumnDeclaration_" + name; }
|
2014-09-24 14:44:57 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr clone() const override
|
2014-09-24 14:44:57 +00:00
|
|
|
{
|
2016-05-28 15:42:22 +00:00
|
|
|
const auto res = std::make_shared<ASTColumnDeclaration>(*this);
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr ptr{res};
|
|
|
|
|
2014-09-24 14:44:57 +00:00
|
|
|
res->children.clear();
|
|
|
|
|
|
|
|
if (type) {
|
|
|
|
res->type = type->clone();
|
|
|
|
res->children.push_back(res->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_expression) {
|
|
|
|
res->default_expression = default_expression->clone();
|
|
|
|
res->children.push_back(res->default_expression);
|
|
|
|
}
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
return ptr;
|
2014-09-24 14:44:57 +00:00
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 14:44:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|