From 5da371b9c0cf5fec54be5f1853f819c49c601982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Thu, 23 Apr 2020 15:39:27 +0300 Subject: [PATCH 01/11] added settings parsing from DDL-query (they aren't applied now) --- src/Parsers/ASTDictionary.h | 7 +++++++ src/Parsers/ParserDictionary.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Parsers/ASTDictionary.h b/src/Parsers/ASTDictionary.h index 6982381f14d..47ae3a2e5c7 100644 --- a/src/Parsers/ASTDictionary.h +++ b/src/Parsers/ASTDictionary.h @@ -5,6 +5,10 @@ #include #include +#include + +#include + namespace DB { @@ -78,6 +82,9 @@ public: /// Range for dictionary (only for range-hashed dictionaries) ASTDictionaryRange * range; + /// Settings for dictionary (optionally) + ASTSetQuery * dict_settings; + String getID(char) const override { return "Dictionary definition"; } ASTPtr clone() const override; diff --git a/src/Parsers/ParserDictionary.cpp b/src/Parsers/ParserDictionary.cpp index 2680c700296..86b156e9079 100644 --- a/src/Parsers/ParserDictionary.cpp +++ b/src/Parsers/ParserDictionary.cpp @@ -11,6 +11,8 @@ #include +#include + namespace DB { @@ -157,6 +159,7 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserKeyword lifetime_keyword("LIFETIME"); ParserKeyword range_keyword("RANGE"); ParserKeyword layout_keyword("LAYOUT"); + ParserKeyword settings_keyword("SETTINGS"); ParserToken open(TokenType::OpeningRoundBracket); ParserToken close(TokenType::ClosingRoundBracket); ParserFunctionWithKeyValueArguments key_value_pairs_p; @@ -164,12 +167,14 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserDictionaryLifetime lifetime_p; ParserDictionaryRange range_p; ParserDictionaryLayout layout_p; + ParserSetQuery settings_p(/* parse_only_internals_ = */ true); ASTPtr primary_key; ASTPtr ast_source; ASTPtr ast_lifetime; ASTPtr ast_layout; ASTPtr ast_range; + ASTPtr ast_settings; /// Primary is required to be the first in dictionary definition if (primary_key_keyword.ignore(pos) && !expression_list_p.parse(pos, primary_key, expected)) @@ -235,6 +240,16 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) continue; } + if (settings_keyword.ignore(pos, expected)) + { + if (!open.ignore(pos)) + return false; + if (!settings_p.parse(pos, ast_settings, expected)) + return false; + if (!close.ignore(pos)) + return false; + } + break; } @@ -255,6 +270,9 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (ast_range) query->set(query->range, ast_range); + if (ast_settings) + query->set(query->dict_settings, ast_settings); + return true; } From f39fdf7182ac095d31d10ae8544f874a30469bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Thu, 23 Apr 2020 23:50:01 +0300 Subject: [PATCH 02/11] some progress in parsing settings (i did this commit for having something to backup to) --- .../getDictionaryConfigurationFromAST.cpp | 16 +++++++++-- src/Parsers/ASTDictionary.cpp | 28 +++++++++++++++++++ src/Parsers/ASTDictionary.h | 15 ++++++++-- src/Parsers/CommonParsers.cpp | 18 +++++++++--- src/Parsers/ParserDictionary.cpp | 21 ++++++++++++-- src/Parsers/ParserDictionary.h | 11 ++++++++ 6 files changed, 98 insertions(+), 11 deletions(-) diff --git a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index e011db9bbce..d7dd06968a0 100644 --- a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -375,13 +375,25 @@ void buildConfigurationFromFunctionWithKeyValueArguments( * * */ -void buildSourceConfiguration(AutoPtr doc, AutoPtr root, const ASTFunctionWithKeyValueArguments * source) +void buildSourceConfiguration(AutoPtr doc, AutoPtr root, const ASTFunctionWithKeyValueArguments * source, const ASTDictionarySettings * settings) { AutoPtr outer_element(doc->createElement("source")); root->appendChild(outer_element); AutoPtr source_element(doc->createElement(source->name)); outer_element->appendChild(source_element); buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as()); + + if (settings != nullptr) { + std::cerr << "PARSING SETTINGS TO XML\n"; + AutoPtr settings_element(doc->createElement("settings")); + outer_element->appendChild(settings_element); + for (const auto & [name, value] : settings->changes) { + AutoPtr setting_change_element(doc->createElement(name)); + settings_element->appendChild(setting_change_element); + AutoPtr setting_value(doc->createTextNode(getFieldAsString(value))); + setting_change_element->appendChild(setting_value); + } + } } /** Check all AST fields are filled, throws exception @@ -454,7 +466,7 @@ DictionaryConfigurationPtr getDictionaryConfigurationFromAST(const ASTCreateQuer buildPrimaryKeyConfiguration(xml_document, structure_element, complex, pk_attrs, query.dictionary_attributes_list); buildLayoutConfiguration(xml_document, current_dictionary, dictionary_layout); - buildSourceConfiguration(xml_document, current_dictionary, query.dictionary->source); + buildSourceConfiguration(xml_document, current_dictionary, query.dictionary->source, query.dictionary->dict_settings); buildLifetimeConfiguration(xml_document, current_dictionary, query.dictionary->lifetime); if (query.dictionary->range) diff --git a/src/Parsers/ASTDictionary.cpp b/src/Parsers/ASTDictionary.cpp index 9ff600333c5..9c732a7ea4f 100644 --- a/src/Parsers/ASTDictionary.cpp +++ b/src/Parsers/ASTDictionary.cpp @@ -107,6 +107,25 @@ void ASTDictionaryLayout::formatImpl(const FormatSettings & settings, settings.ostr << ")"; } +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 : "") << ")"; +} + ASTPtr ASTDictionary::clone() const { @@ -128,6 +147,9 @@ ASTPtr ASTDictionary::clone() const if (range) res->set(res->range, range->clone()); + if (dict_settings) + res->set(res->dict_settings, range->clone()); + return res; } @@ -166,6 +188,12 @@ void ASTDictionary::formatImpl(const FormatSettings & settings, FormatState & st settings.ostr << settings.nl_or_ws; range->formatImpl(settings, state, frame); } + + if (dict_settings) + { + settings.ostr << settings.nl_or_ws; + dict_settings->formatImpl(settings, state, frame); + } } } diff --git a/src/Parsers/ASTDictionary.h b/src/Parsers/ASTDictionary.h index 47ae3a2e5c7..0099ff560ac 100644 --- a/src/Parsers/ASTDictionary.h +++ b/src/Parsers/ASTDictionary.h @@ -64,6 +64,18 @@ public: void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; }; +class ASTDictionarySettings : public IAST +{ +public: + SettingsChanges changes; + + String getID(char) const override { return "Dictionary settings"; } + + ASTPtr clone() const override { return std::make_shared(*this); } + + void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; +}; + /// AST contains all parts of external dictionary definition except attributes class ASTDictionary : public IAST @@ -81,9 +93,8 @@ public: ASTDictionaryLayout * layout; /// Range for dictionary (only for range-hashed dictionaries) ASTDictionaryRange * range; - /// Settings for dictionary (optionally) - ASTSetQuery * dict_settings; + ASTDictionarySettings * dict_settings; String getID(char) const override { return "Dictionary definition"; } diff --git a/src/Parsers/CommonParsers.cpp b/src/Parsers/CommonParsers.cpp index 47868f5df48..4af5af362a2 100644 --- a/src/Parsers/CommonParsers.cpp +++ b/src/Parsers/CommonParsers.cpp @@ -27,8 +27,15 @@ const char * ParserKeyword::getName() const bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) { - if (pos->type != TokenType::BareWord) + if (pos->type != TokenType::BareWord) { +/* + if (strncasecmp(s, "SETTINGS", strlen(s)) == 0) { + std::cerr << "FALSE 0\n"; + std::cerr << getTokenName(pos.get().type) << '\n'; + } +*/ return false; + } const char * current_word = s; @@ -41,17 +48,20 @@ bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) while (true) { expected.add(pos, current_word); - if (pos->type != TokenType::BareWord) + if (pos->type != TokenType::BareWord) { return false; + } const char * next_whitespace = find_first_symbols<' ', '\0'>(current_word, s_end); size_t word_length = next_whitespace - current_word; - if (word_length != pos->size()) + if (word_length != pos->size()) { return false; + } - if (0 != strncasecmp(pos->begin, current_word, word_length)) + if (0 != strncasecmp(pos->begin, current_word, word_length)) { return false; + } ++pos; diff --git a/src/Parsers/ParserDictionary.cpp b/src/Parsers/ParserDictionary.cpp index 86b156e9079..8357979e8ba 100644 --- a/src/Parsers/ParserDictionary.cpp +++ b/src/Parsers/ParserDictionary.cpp @@ -12,6 +12,7 @@ #include #include +#include namespace DB { @@ -167,7 +168,7 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserDictionaryLifetime lifetime_p; ParserDictionaryRange range_p; ParserDictionaryLayout layout_p; - ParserSetQuery settings_p(/* parse_only_internals_ = */ true); + ParserDictionarySettings settings_p; ASTPtr primary_key; ASTPtr ast_source; @@ -240,14 +241,22 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) continue; } - if (settings_keyword.ignore(pos, expected)) + // std::cerr << "GETTING BOOL\n"; + bool tmp = settings_keyword.ignore(pos, expected); + // std::cerr << tmp << "\n"; + if (!ast_settings && tmp) { + std::cerr << "PARSING QUERY\n"; if (!open.ignore(pos)) return false; + if (!settings_p.parse(pos, ast_settings, expected)) return false; + if (!close.ignore(pos)) return false; + + continue; } break; @@ -270,9 +279,15 @@ bool ParserDictionary::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (ast_range) query->set(query->range, ast_range); - if (ast_settings) + // std::cerr << "LOL\n"; + 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; } diff --git a/src/Parsers/ParserDictionary.h b/src/Parsers/ParserDictionary.h index 3e91a72ee81..98992c34b1d 100644 --- a/src/Parsers/ParserDictionary.h +++ b/src/Parsers/ParserDictionary.h @@ -3,6 +3,8 @@ #include #include +#include + namespace DB { @@ -37,6 +39,15 @@ protected: bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; }; +class ParserDictionarySettings: public ParserSetQuery +{ +public: + explicit ParserDictionarySettings() { parse_only_internals = true; } + +protected: + const char * getName() const override { return "settings definition"; } +}; + /// Combines together all parsers from above and also parses primary key and /// dictionary source, which consists of custom key-value pairs: From d7e27d4326cbb2bcaa63d099211fa0c423258dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 00:57:40 +0300 Subject: [PATCH 03/11] added SETTINGS section to DDL-query for CREATE DICTIONARY --- .../getDictionaryConfigurationFromAST.cpp | 1 - src/Parsers/ASTDictionary.cpp | 11 +++++- src/Parsers/ASTDictionary.h | 2 +- src/Parsers/CommonParsers.cpp | 9 +---- src/Parsers/ParserDictionary.cpp | 39 +++++++++++++------ src/Parsers/ParserDictionary.h | 6 +-- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index d7dd06968a0..102c7b7ce6e 100644 --- a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -384,7 +384,6 @@ void buildSourceConfiguration(AutoPtr doc, AutoPtr root, cons buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as()); if (settings != nullptr) { - std::cerr << "PARSING SETTINGS TO XML\n"; AutoPtr settings_element(doc->createElement("settings")); outer_element->appendChild(settings_element); for (const auto & [name, value] : settings->changes) { diff --git a/src/Parsers/ASTDictionary.cpp b/src/Parsers/ASTDictionary.cpp index 9c732a7ea4f..c90c6defd27 100644 --- a/src/Parsers/ASTDictionary.cpp +++ b/src/Parsers/ASTDictionary.cpp @@ -107,6 +107,15 @@ void ASTDictionaryLayout::formatImpl(const FormatSettings & settings, settings.ostr << ")"; } +ASTPtr ASTDictionarySettings::clone() const +{ + auto res = std::make_shared(*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; } diff --git a/src/Parsers/ASTDictionary.h b/src/Parsers/ASTDictionary.h index 0099ff560ac..16a34850bd1 100644 --- a/src/Parsers/ASTDictionary.h +++ b/src/Parsers/ASTDictionary.h @@ -71,7 +71,7 @@ public: String getID(char) const override { return "Dictionary settings"; } - ASTPtr clone() const override { return std::make_shared(*this); } + ASTPtr clone() const override; // { return std::make_shared(*this); } void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; }; diff --git a/src/Parsers/CommonParsers.cpp b/src/Parsers/CommonParsers.cpp index 4af5af362a2..986c32c6475 100644 --- a/src/Parsers/CommonParsers.cpp +++ b/src/Parsers/CommonParsers.cpp @@ -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; diff --git a/src/Parsers/ParserDictionary.cpp b/src/Parsers/ParserDictionary.cpp index 8357979e8ba..f602ece7ba8 100644 --- a/src/Parsers/ParserDictionary.cpp +++ b/src/Parsers/ParserDictionary.cpp @@ -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(); + 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; } diff --git a/src/Parsers/ParserDictionary.h b/src/Parsers/ParserDictionary.h index 98992c34b1d..795a2c618db 100644 --- a/src/Parsers/ParserDictionary.h +++ b/src/Parsers/ParserDictionary.h @@ -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; }; From 69fef04a4b913f82019543f2b656ed390e791a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 02:12:45 +0300 Subject: [PATCH 04/11] added test --- ...9_dictionary_custom_settings_ddl.reference | 2 + .../01259_dictionary_custom_settings_ddl.sql | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.reference create mode 100644 tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.sql diff --git a/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.reference b/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.reference new file mode 100644 index 00000000000..39998d57011 --- /dev/null +++ b/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.reference @@ -0,0 +1,2 @@ +INITIALIZING DICTIONARY +END diff --git a/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.sql b/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.sql new file mode 100644 index 00000000000..cbac234305d --- /dev/null +++ b/tests/queries/0_stateless/01259_dictionary_custom_settings_ddl.sql @@ -0,0 +1,47 @@ +DROP DATABASE IF EXISTS database_for_dict; + +CREATE DATABASE database_for_dict Engine = Ordinary; + +DROP TABLE IF EXISTS database_for_dict.table_for_dict; + +CREATE TABLE database_for_dict.table_for_dict +( + key_column UInt64, + second_column UInt64, + third_column String +) +ENGINE = MergeTree() +ORDER BY key_column; + +INSERT INTO database_for_dict.table_for_dict VALUES (100500, 10000000, 'Hello world'); + +DROP DATABASE IF EXISTS ordinary_db; + +CREATE DATABASE ordinary_db ENGINE = Ordinary; + +DROP DICTIONARY IF EXISTS ordinary_db.dict1; + +CREATE DICTIONARY ordinary_db.dict1 +( + key_column UInt64 DEFAULT 0, + second_column UInt64 DEFAULT 1, + third_column String DEFAULT 'qqq' +) +PRIMARY KEY key_column +SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict')) +LIFETIME(MIN 1 MAX 10) +LAYOUT(FLAT()) SETTINGS(max_result_bytes=1); + +SELECT 'INITIALIZING DICTIONARY'; + +SELECT dictGetUInt64('ordinary_db.dict1', 'second_column', toUInt64(100500)); -- { serverError 396 } + +SELECT 'END'; + +DROP DICTIONARY IF EXISTS ordinary_db.dict1; + +DROP DATABASE IF EXISTS ordinary_db; + +DROP TABLE IF EXISTS database_for_dict.table_for_dict; + +DROP DATABASE IF EXISTS database_for_dict; From aab2e8f9c1ce23a9d0dbbe8d793c3508663e2228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 02:21:51 +0300 Subject: [PATCH 05/11] unsignificant change --- src/Parsers/CommonParsers.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Parsers/CommonParsers.cpp b/src/Parsers/CommonParsers.cpp index 986c32c6475..47868f5df48 100644 --- a/src/Parsers/CommonParsers.cpp +++ b/src/Parsers/CommonParsers.cpp @@ -41,20 +41,17 @@ bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected) while (true) { expected.add(pos, current_word); - if (pos->type != TokenType::BareWord) { + if (pos->type != TokenType::BareWord) return false; - } const char * next_whitespace = find_first_symbols<' ', '\0'>(current_word, s_end); size_t word_length = next_whitespace - current_word; - if (word_length != pos->size()) { + if (word_length != pos->size()) return false; - } - if (0 != strncasecmp(pos->begin, current_word, word_length)) { + if (0 != strncasecmp(pos->begin, current_word, word_length)) return false; - } ++pos; From 26a6353284bb4328410951294af0bd0654f6549a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 12:59:49 +0300 Subject: [PATCH 06/11] tried to fix build fail & fixed codestyle --- src/Dictionaries/getDictionaryConfigurationFromAST.cpp | 6 ++++-- src/Parsers/ParserDictionary.cpp | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index 102c7b7ce6e..3ac3827165b 100644 --- a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -383,10 +383,12 @@ void buildSourceConfiguration(AutoPtr doc, AutoPtr root, cons outer_element->appendChild(source_element); buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as()); - if (settings != nullptr) { + if (settings != nullptr) + { AutoPtr settings_element(doc->createElement("settings")); outer_element->appendChild(settings_element); - for (const auto & [name, value] : settings->changes) { + for (const auto & [name, value] : settings->changes) + { AutoPtr setting_change_element(doc->createElement(name)); settings_element->appendChild(setting_change_element); AutoPtr setting_value(doc->createTextNode(getFieldAsString(value))); diff --git a/src/Parsers/ParserDictionary.cpp b/src/Parsers/ParserDictionary.cpp index f602ece7ba8..77670236d36 100644 --- a/src/Parsers/ParserDictionary.cpp +++ b/src/Parsers/ParserDictionary.cpp @@ -11,7 +11,6 @@ #include -#include #include namespace DB From 5423506393344f70756bf74c2438cfdc8db84820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 19:04:54 +0300 Subject: [PATCH 07/11] sure this will exactly fix the fail with build check --- src/Parsers/ParserDictionary.cpp | 4 ++-- src/Parsers/ParserSetQuery.cpp | 2 +- src/Parsers/ParserSetQuery.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Parsers/ParserDictionary.cpp b/src/Parsers/ParserDictionary.cpp index 77670236d36..a18e5be8975 100644 --- a/src/Parsers/ParserDictionary.cpp +++ b/src/Parsers/ParserDictionary.cpp @@ -11,7 +11,7 @@ #include -#include +#include namespace DB { @@ -164,7 +164,7 @@ bool ParserDictionarySettings::parseImpl(Pos & pos, ASTPtr & node, Expected & ex changes.push_back(SettingChange{}); - if (!parseNameValuePair(changes.back(), pos, expected)) + if (!ParserSetQuery::parseNameValuePair(changes.back(), pos, expected)) return false; } diff --git a/src/Parsers/ParserSetQuery.cpp b/src/Parsers/ParserSetQuery.cpp index 99b08bff337..30d681cb126 100644 --- a/src/Parsers/ParserSetQuery.cpp +++ b/src/Parsers/ParserSetQuery.cpp @@ -13,7 +13,7 @@ namespace DB /// Parse `name = value`. -static bool parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected) +bool ParserSetQuery::parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected) { ParserIdentifier name_p; ParserLiteral value_p; diff --git a/src/Parsers/ParserSetQuery.h b/src/Parsers/ParserSetQuery.h index 13bc30acfce..59a6109ea48 100644 --- a/src/Parsers/ParserSetQuery.h +++ b/src/Parsers/ParserSetQuery.h @@ -14,11 +14,10 @@ class ParserSetQuery : public IParserBase { public: explicit ParserSetQuery(bool parse_only_internals_ = false) : parse_only_internals(parse_only_internals_) {} - + static bool parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected); protected: const char * getName() const override { return "SET query"; } bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; - /// Parse the list `name = value` pairs, without SET. bool parse_only_internals; }; From 091d631b72da782f7934e98fcb6fc8f6017b675b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 22:28:11 +0300 Subject: [PATCH 08/11] documentation edit --- .../external_dicts_dict_sources.md | 12 +++++++----- .../external_dicts_dict_sources.md | 13 +++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md b/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md index ca8aef24ea1..8f82f3ad5db 100644 --- a/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md +++ b/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md @@ -35,11 +35,7 @@ SOURCE(SOURCE_TYPE(param1 val1 ... paramN valN)) -- Source configuration The source is configured in the `source` section. -For source types -[Local file](#dicts-external_dicts_dict_sources-local_file), -[Executable file](#dicts-external_dicts_dict_sources-executable), -[HTTP(s)](#dicts-external_dicts_dict_sources-http), -[ClickHouse](#dicts-external_dicts_dict_sources-clickhouse) +For source types [Local file](#dicts-external_dicts_dict_sources-local_file), [Executable file](#dicts-external_dicts_dict_sources-executable), [HTTP(s)](#dicts-external_dicts_dict_sources-http), [ClickHouse](#dicts-external_dicts_dict_sources-clickhouse) optional settings are available: ``` xml @@ -53,6 +49,12 @@ optional settings are available: ``` +or +``` sql +SOURCE(FILE(path '/opt/dictionaries/os.tsv' format 'TabSeparated')) +SETTINGS(format_csv_allow_single_quotes = 1) +``` + Types of sources (`source_type`): diff --git a/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md b/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md index 102a7cc0e7f..78ccb751643 100644 --- a/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md +++ b/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md @@ -30,11 +30,7 @@ SOURCE(SOURCE_TYPE(param1 val1 ... paramN valN)) -- Source configuration Источник настраивается в разделе `source`. -Для типов источников -[Локальный файл](#dicts-external_dicts_dict_sources-local_file), -[Исполняемый файл](#dicts-external_dicts_dict_sources-executable), -[HTTP(s)](#dicts-external_dicts_dict_sources-http), -[ClickHouse](#dicts-external_dicts_dict_sources-clickhouse) +Для типов источников [Локальный файл](#dicts-external_dicts_dict_sources-local_file), [Исполняемый файл](#dicts-external_dicts_dict_sources-executable), [HTTP(s)](#dicts-external_dicts_dict_sources-http), [ClickHouse](#dicts-external_dicts_dict_sources-clickhouse) доступны дополнительные настройки: ``` xml @@ -44,10 +40,15 @@ SOURCE(SOURCE_TYPE(param1 val1 ... paramN valN)) -- Source configuration TabSeparated - 0 + 0/format_csv_allow_single_quotes> ``` +или +``` sql +SOURCE(FILE(path '/opt/dictionaries/os.tsv' format 'TabSeparated')) +SETTINGS(format_csv_allow_single_quotes = 0) +``` Типы источников (`source_type`): From 96de73fb37d83f4ccde246b7341d82a21a17f65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 22:30:14 +0300 Subject: [PATCH 09/11] documentation edit (previous had mistypes) --- .../external_dictionaries/external_dicts_dict_sources.md | 2 +- .../external_dictionaries/external_dicts_dict_sources.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md b/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md index 8f82f3ad5db..a5c40226f85 100644 --- a/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md +++ b/docs/en/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md @@ -52,7 +52,7 @@ optional settings are available: or ``` sql SOURCE(FILE(path '/opt/dictionaries/os.tsv' format 'TabSeparated')) -SETTINGS(format_csv_allow_single_quotes = 1) +SETTINGS(format_csv_allow_single_quotes = 0) ``` diff --git a/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md b/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md index 78ccb751643..ae3bb57fae7 100644 --- a/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md +++ b/docs/ru/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md @@ -40,7 +40,7 @@ SOURCE(SOURCE_TYPE(param1 val1 ... paramN valN)) -- Source configuration TabSeparated - 0/format_csv_allow_single_quotes> + 0 ``` From 6fa25f16f8dff697edd3e8f3c1cdd9836f9eda8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D1=86=D0=BE=D0=B2?= Date: Fri, 24 Apr 2020 22:35:23 +0300 Subject: [PATCH 10/11] french documentation edited too --- .../external_dicts_dict_sources.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/fr/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md b/docs/fr/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md index 55a982862ed..f5027311e76 100644 --- a/docs/fr/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md +++ b/docs/fr/sql_reference/dictionaries/external_dictionaries/external_dicts_dict_sources.md @@ -37,6 +37,20 @@ SOURCE(SOURCE_TYPE(param1 val1 ... paramN valN)) -- Source configuration La source est configurée dans le `source` section. +Pour les sources de types [Fichier Local](#dicts-external_dicts_dict_sources-local_file), [Fichier exécutable](#dicts-external_dicts_dict_sources-executable), [HTTP(s)](#dicts-external_dicts_dict_sources-http), [ClickHouse](#dicts-external_dicts_dict_sources-clickhouse) +les paramètres optionnels sont possibles: + +``` xml +@@ -53,6 +49,12 @@ optional settings are available: + + +``` +ou +``` sql +SOURCE(FILE(path '/opt/dictionaries/os.tsv' format 'TabSeparated')) +SETTINGS(format_csv_allow_single_quotes = 1) +``` + Les Types de sources (`source_type`): - [Fichier Local](#dicts-external_dicts_dict_sources-local_file) From 7d58dc154c47df503b1893fe664cb3a54267f68b Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Sun, 26 Apr 2020 20:24:18 +0300 Subject: [PATCH 11/11] Update ASTDictionary.h --- src/Parsers/ASTDictionary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parsers/ASTDictionary.h b/src/Parsers/ASTDictionary.h index 16a34850bd1..9685cc5a83a 100644 --- a/src/Parsers/ASTDictionary.h +++ b/src/Parsers/ASTDictionary.h @@ -71,7 +71,7 @@ public: String getID(char) const override { return "Dictionary settings"; } - ASTPtr clone() const override; // { return std::make_shared(*this); } + ASTPtr clone() const override; void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; };