mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Merge pull request #21884 from kitaisreal/system-dictionaries-updated
Improve system.dictionaries table
This commit is contained in:
commit
95c87d4ded
@ -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)
|
||||
|
@ -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
|
||||
|
@ -30,7 +30,8 @@ NamesAndTypesList StorageSystemDictionaries::getNamesAndTypes()
|
||||
{"status", std::make_shared<DataTypeEnum8>(getStatusEnumAllPossibleValues())},
|
||||
{"origin", std::make_shared<DataTypeString>()},
|
||||
{"type", std::make_shared<DataTypeString>()},
|
||||
{"key", std::make_shared<DataTypeString>()},
|
||||
{"key.names", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
||||
{"key.types", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
||||
{"attribute.names", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
||||
{"attribute.types", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
||||
{"bytes_allocated", std::make_shared<DataTypeUInt64>()},
|
||||
@ -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<const IDictionaryBase>(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<Array>(dict_struct.attributes, [] (auto & attr) { return attr.name; }));
|
||||
res_columns[i++]->insert(ext::map<Array>(dict_struct.attributes, [] (auto & attr) { return attr.type->getName(); }));
|
||||
res_columns[i++]->insert(ext::map<Array>(dictionary_structure.getKeysNames(), [] (auto & name) { return name; }));
|
||||
|
||||
if (dictionary_structure.id)
|
||||
res_columns[i++]->insert(Array({"UInt64"}));
|
||||
else
|
||||
res_columns[i++]->insert(ext::map<Array>(*dictionary_structure.key, [] (auto & attr) { return attr.type->getName(); }));
|
||||
|
||||
res_columns[i++]->insert(ext::map<Array>(dictionary_structure.attributes, [] (auto & attr) { return attr.name; }));
|
||||
res_columns[i++]->insert(ext::map<Array>(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();
|
||||
}
|
||||
|
||||
|
@ -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
|
57
tests/queries/0_stateless/01760_system_dictionaries.sql
Normal file
57
tests/queries/0_stateless/01760_system_dictionaries.sql
Normal file
@ -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;
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user