added SETTINGS section to DDL-query for CREATE DICTIONARY

This commit is contained in:
Артем Стрельцов 2020-04-24 00:57:40 +03:00
parent f39fdf7182
commit d7e27d4326
6 changed files with 41 additions and 27 deletions

View File

@ -384,7 +384,6 @@ void buildSourceConfiguration(AutoPtr<Document> doc, AutoPtr<Element> root, cons
buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as<const ASTExpressionList>());
if (settings != nullptr) {
std::cerr << "PARSING SETTINGS TO XML\n";
AutoPtr<Element> settings_element(doc->createElement("settings"));
outer_element->appendChild(settings_element);
for (const auto & [name, value] : settings->changes) {

View File

@ -107,6 +107,15 @@ void ASTDictionaryLayout::formatImpl(const FormatSettings & settings,
settings.ostr << ")";
}
ASTPtr ASTDictionarySettings::clone() const
{
auto res = std::make_shared<ASTDictionarySettings>(*this);
res->children.clear();
res->changes = changes;
return res;
}
void ASTDictionarySettings::formatImpl(const FormatSettings & settings,
FormatState &,
FormatStateStacked) const
@ -148,7 +157,7 @@ ASTPtr ASTDictionary::clone() const
res->set(res->range, range->clone());
if (dict_settings)
res->set(res->dict_settings, range->clone());
res->set(res->dict_settings, dict_settings->clone());
return res;
}

View File

@ -71,7 +71,7 @@ public:
String getID(char) const override { return "Dictionary settings"; }
ASTPtr clone() const override { return std::make_shared<ASTDictionarySettings>(*this); }
ASTPtr clone() const override; // { return std::make_shared<ASTDictionarySettings>(*this); }
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
};

View File

@ -27,15 +27,8 @@ const char * ParserKeyword::getName() const
bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected)
{
if (pos->type != TokenType::BareWord) {
/*
if (strncasecmp(s, "SETTINGS", strlen(s)) == 0) {
std::cerr << "FALSE 0\n";
std::cerr << getTokenName(pos.get().type) << '\n';
}
*/
if (pos->type != TokenType::BareWord)
return false;
}
const char * current_word = s;

View File

@ -152,6 +152,31 @@ bool ParserDictionaryLayout::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
return true;
}
bool ParserDictionarySettings::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserToken s_comma(TokenType::Comma);
SettingsChanges changes;
while (true)
{
if (!changes.empty() && !s_comma.ignore(pos))
break;
changes.push_back(SettingChange{});
if (!parseNameValuePair(changes.back(), pos, expected))
return false;
}
auto query = std::make_shared<ASTDictionarySettings>();
query->changes = std::move(changes);
node = query;
return true;
}
bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
@ -241,12 +266,8 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
continue;
}
// std::cerr << "GETTING BOOL\n";
bool tmp = settings_keyword.ignore(pos, expected);
// std::cerr << tmp << "\n";
if (!ast_settings && tmp)
if (!ast_settings && settings_keyword.ignore(pos, expected))
{
std::cerr << "PARSING QUERY\n";
if (!open.ignore(pos))
return false;
@ -279,15 +300,9 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (ast_range)
query->set(query->range, ast_range);
// std::cerr << "LOL\n";
if (ast_settings) {
if (ast_settings)
query->set(query->dict_settings, ast_settings);
for (const auto & [name, value] : query->dict_settings->changes) {
std::cerr << "DEBUG: " << name << '\n';
}
}
return true;
}

View File

@ -39,13 +39,11 @@ protected:
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
};
class ParserDictionarySettings: public ParserSetQuery
class ParserDictionarySettings: public IParserBase
{
public:
explicit ParserDictionarySettings() { parse_only_internals = true; }
protected:
const char * getName() const override { return "settings definition"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
};