diff --git a/src/Dictionaries/DictionaryFactory.cpp b/src/Dictionaries/DictionaryFactory.cpp index 9b7fbbf7c68..92ff269a5ac 100644 --- a/src/Dictionaries/DictionaryFactory.cpp +++ b/src/Dictionaries/DictionaryFactory.cpp @@ -55,7 +55,11 @@ DictionaryPtr DictionaryFactory::create( if (found != registered_layouts.end()) { const auto & layout_creator = found->second.layout_create_function; - return layout_creator(name, dict_struct, config, config_prefix, std::move(source_ptr), global_context, created_from_ddl); + auto result = layout_creator(name, dict_struct, config, config_prefix, std::move(source_ptr), global_context, created_from_ddl); + if (config.hasProperty(config_prefix + ".comment")) + result->setDictionaryComment(config.getString(config_prefix + ".comment")); + + return result; } } diff --git a/src/Dictionaries/IDictionary.h b/src/Dictionaries/IDictionary.h index a62fb4a788e..b40dc418c66 100644 --- a/src/Dictionaries/IDictionary.h +++ b/src/Dictionaries/IDictionary.h @@ -216,12 +216,25 @@ struct IDictionary : public IExternalLoadable return std::static_pointer_cast(IExternalLoadable::shared_from_this()); } + void setDictionaryComment(String new_comment) + { + std::lock_guard lock{name_mutex}; + dictionary_comment = std::move(new_comment); + } + + String getDictionaryComment() const + { + std::lock_guard lock{name_mutex}; + return dictionary_comment; + } + private: mutable std::mutex name_mutex; mutable StorageID dictionary_id; protected: const String full_name; + String dictionary_comment; }; } diff --git a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index 341a89bfc06..0c6944eeccc 100644 --- a/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -573,6 +573,15 @@ getDictionaryConfigurationFromAST(const ASTCreateQuery & query, ContextPtr conte if (query.dictionary->range) buildRangeConfiguration(xml_document, structure_element, query.dictionary->range, all_attr_names_and_types); + if (query.comment) + { + AutoPtr comment_element(xml_document->createElement("comment")); + current_dictionary->appendChild(comment_element); + AutoPtr comment_value(xml_document->createTextNode(query.comment->as()->value.safeGet())); + + comment_element->appendChild(comment_value); + } + conf->load(xml_document); return conf; } diff --git a/src/Storages/System/StorageSystemDictionaries.cpp b/src/Storages/System/StorageSystemDictionaries.cpp index 0826bb58473..d8f92d38081 100644 --- a/src/Storages/System/StorageSystemDictionaries.cpp +++ b/src/Storages/System/StorageSystemDictionaries.cpp @@ -47,7 +47,8 @@ NamesAndTypesList StorageSystemDictionaries::getNamesAndTypes() {"last_successful_update_time", std::make_shared()}, {"loading_duration", std::make_shared()}, //{ "creation_time", std::make_shared() }, - {"last_exception", std::make_shared()} + {"last_exception", std::make_shared()}, + {"comment", std::make_shared()} }; } @@ -140,6 +141,16 @@ void StorageSystemDictionaries::fillData(MutableColumns & res_columns, ContextPt else res_columns[i++]->insertDefault(); + if (dict_ptr) + res_columns[i++]->insert(dict_ptr->getDictionaryComment()); + else + { + if (load_result.config && load_result.config->config->has("dictionary.comment")) + res_columns[i++]->insert(load_result.config->config->getString("dictionary.comment")); + else + res_columns[i++]->insertDefault(); + } + /// Start fill virtual columns res_columns[i++]->insert(dictionary_structure.getKeyDescription()); diff --git a/tests/queries/0_stateless/02024_create_dictionary_with_comment.reference b/tests/queries/0_stateless/02024_create_dictionary_with_comment.reference index e69de29bb2d..45f2c41f0b0 100644 --- a/tests/queries/0_stateless/02024_create_dictionary_with_comment.reference +++ b/tests/queries/0_stateless/02024_create_dictionary_with_comment.reference @@ -0,0 +1,2 @@ +CREATE DICTIONARY default.`2024_dictionary_with_comment`\n(\n `id` UInt64,\n `value` String\n)\nPRIMARY KEY id\nSOURCE(CLICKHOUSE(HOST \'localhost\' PORT tcpPort() TABLE \'source_table\'))\nLIFETIME(MIN 0 MAX 1000)\nLAYOUT(FLAT())\nCOMMENT \'Test dictionary with comment\' +Test dictionary with comment diff --git a/tests/queries/0_stateless/02024_create_dictionary_with_comment.sql b/tests/queries/0_stateless/02024_create_dictionary_with_comment.sql index de71d0d976b..bbe2fa7066b 100644 --- a/tests/queries/0_stateless/02024_create_dictionary_with_comment.sql +++ b/tests/queries/0_stateless/02024_create_dictionary_with_comment.sql @@ -28,5 +28,6 @@ LIFETIME(MIN 0 MAX 1000) COMMENT 'Test dictionary with comment'; SHOW CREATE DICTIONARY 2024_dictionary_with_comment; +SELECT comment FROM system.dictionaries WHERE name == '2024_dictionary_with_comment' AND database == currentDatabase(); -SELECT comment FROM system.dictionaries WHERE name == '2024_dictionary_with_comment'; \ No newline at end of file +DROP DICTIONARY IF EXISTS 2024_dictionary_with_comment; \ No newline at end of file