diff --git a/src/Dictionaries/DictionaryStructure.cpp b/src/Dictionaries/DictionaryStructure.cpp index 1e8e9ee58dc..ea3e3efa03d 100644 --- a/src/Dictionaries/DictionaryStructure.cpp +++ b/src/Dictionaries/DictionaryStructure.cpp @@ -306,14 +306,6 @@ bool DictionaryStructure::isKeySizeFixed() const return true; } -size_t DictionaryStructure::getKeySize() const -{ - return std::accumulate(std::begin(*key), std::end(*key), size_t{}, [](const auto running_size, const auto & key_i) - { - return running_size + key_i.type->getSizeOfValueInMemory(); - }); -} - Strings DictionaryStructure::getKeysNames() const { if (id) diff --git a/src/Dictionaries/DictionaryStructure.h b/src/Dictionaries/DictionaryStructure.h index 08cc49aeb85..39332f2dff2 100644 --- a/src/Dictionaries/DictionaryStructure.h +++ b/src/Dictionaries/DictionaryStructure.h @@ -161,12 +161,12 @@ struct DictionaryStructure final const DictionaryAttribute & getAttribute(const std::string & attribute_name) const; const DictionaryAttribute & getAttribute(const std::string & attribute_name, const DataTypePtr & type) const; + + Strings getKeysNames() const; size_t getKeysSize() const; std::string getKeyDescription() const; bool isKeySizeFixed() const; - size_t getKeySize() const; - Strings getKeysNames() const; private: /// range_min and range_max have to be parsed before this function call diff --git a/src/Storages/System/StorageSystemDictionaries.cpp b/src/Storages/System/StorageSystemDictionaries.cpp index 6661f51b02f..cccd23ffbd1 100644 --- a/src/Storages/System/StorageSystemDictionaries.cpp +++ b/src/Storages/System/StorageSystemDictionaries.cpp @@ -30,7 +30,8 @@ NamesAndTypesList StorageSystemDictionaries::getNamesAndTypes() {"status", std::make_shared(getStatusEnumAllPossibleValues())}, {"origin", std::make_shared()}, {"type", std::make_shared()}, - {"key", std::make_shared()}, + {"key.names", std::make_shared(std::make_shared())}, + {"key.types", std::make_shared(std::make_shared())}, {"attribute.names", std::make_shared(std::make_shared())}, {"attribute.types", std::make_shared(std::make_shared())}, {"bytes_allocated", std::make_shared()}, @@ -58,6 +59,7 @@ void StorageSystemDictionaries::fillData(MutableColumns & res_columns, const Con for (const auto & load_result : external_dictionaries.getLoadResults()) { const auto dict_ptr = std::dynamic_pointer_cast(load_result.object); + DictionaryStructure dictionary_structure = ExternalDictionariesLoader::getDictionaryStructure(*load_result.config); StorageID dict_id = StorageID::createEmpty(); if (dict_ptr) @@ -82,13 +84,22 @@ void StorageSystemDictionaries::fillData(MutableColumns & res_columns, const Con std::exception_ptr last_exception = load_result.exception; if (dict_ptr) - { res_columns[i++]->insert(dict_ptr->getTypeName()); + else + res_columns[i++]->insertDefault(); - const auto & dict_struct = dict_ptr->getStructure(); - res_columns[i++]->insert(dict_struct.getKeyDescription()); - res_columns[i++]->insert(ext::map(dict_struct.attributes, [] (auto & attr) { return attr.name; })); - res_columns[i++]->insert(ext::map(dict_struct.attributes, [] (auto & attr) { return attr.type->getName(); })); + res_columns[i++]->insert(ext::map(dictionary_structure.getKeysNames(), [] (auto & name) { return name; })); + + if (dictionary_structure.id) + res_columns[i++]->insert(Array({"UInt64"})); + else + res_columns[i++]->insert(ext::map(*dictionary_structure.key, [] (auto & attr) { return attr.type->getName(); })); + + res_columns[i++]->insert(ext::map(dictionary_structure.attributes, [] (auto & attr) { return attr.name; })); + res_columns[i++]->insert(ext::map(dictionary_structure.attributes, [] (auto & attr) { return attr.type->getName(); })); + + if (dict_ptr) + { res_columns[i++]->insert(dict_ptr->getBytesAllocated()); res_columns[i++]->insert(dict_ptr->getQueryCount()); res_columns[i++]->insert(dict_ptr->getHitRate()); @@ -104,7 +115,7 @@ void StorageSystemDictionaries::fillData(MutableColumns & res_columns, const Con } else { - for (size_t j = 0; j != 12; ++j) // Number of empty fields if dict_ptr is null + for (size_t j = 0; j != 8; ++j) // Number of empty fields if dict_ptr is null res_columns[i++]->insertDefault(); } diff --git a/tests/queries/0_stateless/01760_system_dictionaries.reference b/tests/queries/0_stateless/01760_system_dictionaries.reference new file mode 100644 index 00000000000..aaf160dea69 --- /dev/null +++ b/tests/queries/0_stateless/01760_system_dictionaries.reference @@ -0,0 +1,14 @@ +simple key +example_simple_key_dictionary 01760_db ['id'] ['UInt64'] ['value'] ['UInt64'] NOT_LOADED +example_simple_key_dictionary 01760_db ['id'] ['UInt64'] ['value'] ['UInt64'] NOT_LOADED +0 0 +1 1 +2 2 +example_simple_key_dictionary 01760_db ['id'] ['UInt64'] ['value'] ['UInt64'] LOADED +complex key +example_complex_key_dictionary 01760_db ['id','id_key'] ['UInt64','String'] ['value'] ['UInt64'] NOT_LOADED +example_complex_key_dictionary 01760_db ['id','id_key'] ['UInt64','String'] ['value'] ['UInt64'] NOT_LOADED +0 0_key 0 +1 1_key 1 +2 2_key 2 +example_complex_key_dictionary 01760_db ['id','id_key'] ['UInt64','String'] ['value'] ['UInt64'] LOADED diff --git a/tests/queries/0_stateless/01760_system_dictionaries.sql b/tests/queries/0_stateless/01760_system_dictionaries.sql new file mode 100644 index 00000000000..f4e0cfa0086 --- /dev/null +++ b/tests/queries/0_stateless/01760_system_dictionaries.sql @@ -0,0 +1,57 @@ +DROP DATABASE IF EXISTS 01760_db; +CREATE DATABASE 01760_db; + +DROP TABLE IF EXISTS 01760_db.example_simple_key_source; +CREATE TABLE 01760_db.example_simple_key_source (id UInt64, value UInt64) ENGINE=TinyLog; +INSERT INTO 01760_db.example_simple_key_source VALUES (0, 0), (1, 1), (2, 2); + +DROP DICTIONARY IF EXISTS 01760_db.example_simple_key_dictionary; +CREATE DICTIONARY 01760_db.example_simple_key_dictionary ( + id UInt64, + value UInt64 +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'example_simple_key_source' DATABASE '01760_db')) +LAYOUT(DIRECT()); + +SELECT 'simple key'; + +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; + +SELECT * FROM 01760_db.example_simple_key_dictionary; + +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; + +DROP TABLE 01760_db.example_simple_key_source; +DROP DICTIONARY 01760_db.example_simple_key_dictionary; + +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; + +DROP TABLE IF EXISTS 01760_db.example_complex_key_source; +CREATE TABLE 01760_db.example_complex_key_source (id UInt64, id_key String, value UInt64) ENGINE=TinyLog; +INSERT INTO 01760_db.example_complex_key_source VALUES (0, '0_key', 0), (1, '1_key', 1), (2, '2_key', 2); + +DROP DICTIONARY IF EXISTS 01760_db.example_complex_key_dictionary; +CREATE DICTIONARY 01760_db.example_complex_key_dictionary ( + id UInt64, + id_key String, + value UInt64 +) +PRIMARY KEY id, id_key +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'example_complex_key_source' DATABASE '01760_db')) +LAYOUT(COMPLEX_KEY_DIRECT()); + +SELECT 'complex key'; + +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; + +SELECT * FROM 01760_db.example_complex_key_dictionary; + +SELECT name, database, key.names, key.types, attribute.names, attribute.types, status FROM system.dictionaries WHERE database='01760_db'; + +DROP TABLE 01760_db.example_complex_key_source; +DROP DICTIONARY 01760_db.example_complex_key_dictionary; + +DROP DATABASE 01760_db; diff --git a/tests/queries/skip_list.json b/tests/queries/skip_list.json index b69541a841c..436f0257c94 100644 --- a/tests/queries/skip_list.json +++ b/tests/queries/skip_list.json @@ -775,6 +775,7 @@ "01681_cache_dictionary_simple_key", "01682_cache_dictionary_complex_key", "01684_ssd_cache_dictionary_simple_key", - "01685_ssd_cache_dictionary_complex_key" + "01685_ssd_cache_dictionary_complex_key", + "01760_system_dictionaries" ] }