mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Create dictionary with comment
This commit is contained in:
parent
199eda4ee3
commit
2c55807b2a
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,12 +216,25 @@ struct IDictionary : public IExternalLoadable
|
||||
return std::static_pointer_cast<const IDictionary>(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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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<Element> comment_element(xml_document->createElement("comment"));
|
||||
current_dictionary->appendChild(comment_element);
|
||||
AutoPtr<Text> comment_value(xml_document->createTextNode(query.comment->as<ASTLiteral>()->value.safeGet<String>()));
|
||||
|
||||
comment_element->appendChild(comment_value);
|
||||
}
|
||||
|
||||
conf->load(xml_document);
|
||||
return conf;
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ NamesAndTypesList StorageSystemDictionaries::getNamesAndTypes()
|
||||
{"last_successful_update_time", std::make_shared<DataTypeDateTime>()},
|
||||
{"loading_duration", std::make_shared<DataTypeFloat32>()},
|
||||
//{ "creation_time", std::make_shared<DataTypeDateTime>() },
|
||||
{"last_exception", std::make_shared<DataTypeString>()}
|
||||
{"last_exception", std::make_shared<DataTypeString>()},
|
||||
{"comment", std::make_shared<DataTypeString>()}
|
||||
};
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
@ -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
|
@ -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';
|
||||
DROP DICTIONARY IF EXISTS 2024_dictionary_with_comment;
|
Loading…
Reference in New Issue
Block a user