2019-03-23 22:58:08 +00:00
|
|
|
#include <Parsers/ASTColumnDeclaration.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2019-03-23 22:58:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTColumnDeclaration::clone() const
|
|
|
|
{
|
|
|
|
const auto res = std::make_shared<ASTColumnDeclaration>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
2020-06-02 13:56:10 +00:00
|
|
|
// Type may be an ASTFunction (e.g. `create table t (a Decimal(9,0))`),
|
|
|
|
// so we have to clone it properly as well.
|
|
|
|
res->type = type->clone();
|
2019-03-23 22:58:08 +00:00
|
|
|
res->children.push_back(res->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_expression)
|
|
|
|
{
|
|
|
|
res->default_expression = default_expression->clone();
|
|
|
|
res->children.push_back(res->default_expression);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (comment)
|
|
|
|
{
|
|
|
|
res->comment = comment->clone();
|
|
|
|
res->children.push_back(res->comment);
|
|
|
|
}
|
|
|
|
|
2019-06-16 16:47:47 +00:00
|
|
|
if (codec)
|
|
|
|
{
|
|
|
|
res->codec = codec->clone();
|
|
|
|
res->children.push_back(res->codec);
|
|
|
|
}
|
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
if (ttl)
|
|
|
|
{
|
|
|
|
res->ttl = ttl->clone();
|
|
|
|
res->children.push_back(res->ttl);
|
|
|
|
}
|
|
|
|
|
2019-03-23 22:58:08 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTColumnDeclaration::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
frame.need_parens = false;
|
2019-03-25 21:44:10 +00:00
|
|
|
|
2019-03-23 23:01:57 +00:00
|
|
|
/// We have to always backquote column names to avoid ambiguouty with INDEX and other declarations in CREATE query.
|
2019-03-25 21:44:10 +00:00
|
|
|
settings.ostr << backQuote(name);
|
2019-03-23 23:01:57 +00:00
|
|
|
|
2019-03-23 22:58:08 +00:00
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ';
|
2020-11-04 20:43:11 +00:00
|
|
|
|
2020-11-06 19:11:57 +00:00
|
|
|
FormatStateStacked type_frame = frame;
|
|
|
|
type_frame.indent = 0;
|
2020-11-04 20:43:11 +00:00
|
|
|
|
2020-11-06 19:11:57 +00:00
|
|
|
type->formatImpl(settings, state, type_frame);
|
2019-03-23 22:58:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 16:17:22 +00:00
|
|
|
if (null_modifier)
|
2020-05-20 18:23:35 +00:00
|
|
|
{
|
2020-06-14 16:17:22 +00:00
|
|
|
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< (*null_modifier ? "" : "NOT ") << "NULL" << (settings.hilite ? hilite_none : "");
|
2020-05-20 18:23:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 22:58:08 +00:00
|
|
|
if (default_expression)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << default_specifier << (settings.hilite ? hilite_none : "") << ' ';
|
|
|
|
default_expression->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (comment)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "COMMENT" << (settings.hilite ? hilite_none : "") << ' ';
|
|
|
|
comment->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codec)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ';
|
|
|
|
codec->formatImpl(settings, state, frame);
|
|
|
|
}
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
if (ttl)
|
|
|
|
{
|
|
|
|
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "TTL" << (settings.hilite ? hilite_none : "") << ' ';
|
|
|
|
ttl->formatImpl(settings, state, frame);
|
|
|
|
}
|
2019-03-23 22:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|