2019-10-01 14:54:28 +00:00
|
|
|
#include <Parsers/ASTDictionary.h>
|
|
|
|
#include <Poco/String.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2021-06-14 04:13:35 +00:00
|
|
|
#include <Common/FieldVisitorToString.h>
|
|
|
|
|
2019-10-01 14:54:28 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTDictionaryRange::clone() const
|
|
|
|
{
|
2020-08-03 16:15:52 +00:00
|
|
|
auto res = std::make_shared<ASTDictionaryRange>();
|
2019-10-01 14:54:28 +00:00
|
|
|
res->min_attr_name = min_attr_name;
|
|
|
|
res->max_attr_name = max_attr_name;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTDictionaryRange::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState &,
|
|
|
|
FormatStateStacked) const
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "RANGE"
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< "("
|
|
|
|
<< (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "MIN "
|
2020-04-06 11:02:17 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "")
|
2019-10-11 13:21:52 +00:00
|
|
|
<< min_attr_name << " "
|
2019-10-01 14:54:28 +00:00
|
|
|
<< (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "MAX "
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< max_attr_name << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTPtr ASTDictionaryLifetime::clone() const
|
|
|
|
{
|
2020-08-03 16:15:52 +00:00
|
|
|
auto res = std::make_shared<ASTDictionaryLifetime>();
|
2019-10-01 14:54:28 +00:00
|
|
|
res->min_sec = min_sec;
|
|
|
|
res->max_sec = max_sec;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTDictionaryLifetime::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState &,
|
|
|
|
FormatStateStacked) const
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "LIFETIME"
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< "("
|
|
|
|
<< (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "MIN "
|
2020-04-06 11:02:17 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "")
|
2019-10-11 13:21:52 +00:00
|
|
|
<< min_sec << " "
|
2019-10-01 14:54:28 +00:00
|
|
|
<< (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "MAX "
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< max_sec << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTPtr ASTDictionaryLayout::clone() const
|
|
|
|
{
|
2020-08-03 16:15:52 +00:00
|
|
|
auto res = std::make_shared<ASTDictionaryLayout>();
|
2019-10-01 14:54:28 +00:00
|
|
|
res->layout_type = layout_type;
|
2020-12-04 02:15:44 +00:00
|
|
|
if (parameters) res->set(res->parameters, parameters->clone());
|
2020-08-03 16:15:52 +00:00
|
|
|
res->has_brackets = has_brackets;
|
2019-10-01 14:54:28 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTDictionaryLayout::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState & state,
|
2020-03-08 21:53:03 +00:00
|
|
|
FormatStateStacked frame) const
|
2019-10-01 14:54:28 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "LAYOUT"
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< "("
|
|
|
|
<< (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< Poco::toUpper(layout_type)
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
|
2020-04-06 11:02:17 +00:00
|
|
|
if (has_brackets)
|
|
|
|
settings.ostr << "(";
|
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
if (parameters) parameters->formatImpl(settings, state, frame);
|
2020-04-06 11:02:17 +00:00
|
|
|
|
|
|
|
if (has_brackets)
|
|
|
|
settings.ostr << ")";
|
|
|
|
|
2019-10-01 14:54:28 +00:00
|
|
|
settings.ostr << ")";
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:57:40 +00:00
|
|
|
ASTPtr ASTDictionarySettings::clone() const
|
|
|
|
{
|
2020-08-03 16:15:52 +00:00
|
|
|
auto res = std::make_shared<ASTDictionarySettings>();
|
2020-04-23 21:57:40 +00:00
|
|
|
res->changes = changes;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-04-23 20:50:01 +00:00
|
|
|
void ASTDictionarySettings::formatImpl(const FormatSettings & settings,
|
|
|
|
FormatState &,
|
|
|
|
FormatStateStacked) const
|
|
|
|
{
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< "SETTINGS"
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< "(";
|
|
|
|
for (auto it = changes.begin(); it != changes.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != changes.begin())
|
|
|
|
settings.ostr << ", ";
|
|
|
|
|
|
|
|
settings.ostr << it->name << " = " << applyVisitor(FieldVisitorToString(), it->value);
|
|
|
|
}
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "") << ")";
|
|
|
|
}
|
|
|
|
|
2019-10-01 14:54:28 +00:00
|
|
|
|
|
|
|
ASTPtr ASTDictionary::clone() const
|
|
|
|
{
|
2020-08-03 16:15:52 +00:00
|
|
|
auto res = std::make_shared<ASTDictionary>();
|
2019-10-01 14:54:28 +00:00
|
|
|
|
|
|
|
if (primary_key)
|
|
|
|
res->set(res->primary_key, primary_key->clone());
|
|
|
|
|
2020-08-03 16:15:52 +00:00
|
|
|
if (source)
|
|
|
|
res->set(res->source, source->clone());
|
|
|
|
|
2019-10-01 14:54:28 +00:00
|
|
|
if (lifetime)
|
|
|
|
res->set(res->lifetime, lifetime->clone());
|
|
|
|
|
|
|
|
if (layout)
|
|
|
|
res->set(res->layout, layout->clone());
|
|
|
|
|
|
|
|
if (range)
|
|
|
|
res->set(res->range, range->clone());
|
|
|
|
|
2020-04-23 20:50:01 +00:00
|
|
|
if (dict_settings)
|
2020-04-23 21:57:40 +00:00
|
|
|
res->set(res->dict_settings, dict_settings->clone());
|
2020-04-23 20:50:01 +00:00
|
|
|
|
2019-10-01 14:54:28 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTDictionary::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
if (primary_key)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << settings.nl_or_ws << "PRIMARY KEY "
|
2019-10-11 13:21:52 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "");
|
2019-10-01 14:54:28 +00:00
|
|
|
primary_key->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
2019-10-11 13:21:52 +00:00
|
|
|
{
|
2023-03-15 21:20:56 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << settings.nl_or_ws << "SOURCE"
|
2023-03-21 12:32:03 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
settings.ostr << "(";
|
2019-10-11 13:21:52 +00:00
|
|
|
source->formatImpl(settings, state, frame);
|
|
|
|
settings.ostr << ")";
|
|
|
|
}
|
2019-10-01 14:54:28 +00:00
|
|
|
|
|
|
|
if (lifetime)
|
|
|
|
{
|
|
|
|
settings.ostr << settings.nl_or_ws;
|
|
|
|
lifetime->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout)
|
|
|
|
{
|
|
|
|
settings.ostr << settings.nl_or_ws;
|
|
|
|
layout->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (range)
|
|
|
|
{
|
|
|
|
settings.ostr << settings.nl_or_ws;
|
|
|
|
range->formatImpl(settings, state, frame);
|
|
|
|
}
|
2020-04-23 20:50:01 +00:00
|
|
|
|
|
|
|
if (dict_settings)
|
|
|
|
{
|
|
|
|
settings.ostr << settings.nl_or_ws;
|
|
|
|
dict_settings->formatImpl(settings, state, frame);
|
|
|
|
}
|
2019-10-01 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|