Merge pull request #21668 from kitaisreal/dictionary-attributes-unique-names

DictionaryStructure fix non unique attribute names
This commit is contained in:
Maksim Kita 2021-03-13 12:31:33 +03:00 committed by GitHub
commit 79b061ac3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -354,6 +354,7 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
config.keys(config_prefix, config_elems); config.keys(config_prefix, config_elems);
auto has_hierarchy = false; auto has_hierarchy = false;
std::unordered_set<String> attribute_names;
std::vector<DictionaryAttribute> res_attributes; std::vector<DictionaryAttribute> res_attributes;
const FormatSettings format_settings; const FormatSettings format_settings;
@ -376,6 +377,15 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
if ((range_min && name == range_min->name) || (range_max && name == range_max->name)) if ((range_min && name == range_min->name) || (range_max && name == range_max->name))
continue; continue;
auto insert_result = attribute_names.insert(name);
bool inserted = insert_result.second;
if (!inserted)
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"Dictionary attributes names must be unique. Attribute name ({}) is not unique",
name);
const auto type_string = config.getString(prefix + "type"); const auto type_string = config.getString(prefix + "type");
const auto initial_type = DataTypeFactory::instance().get(type_string); const auto initial_type = DataTypeFactory::instance().get(type_string);
auto type = initial_type; auto type = initial_type;

View File

@ -0,0 +1,3 @@
0 2 3
1 5 6
2 8 9

View File

@ -0,0 +1,32 @@
DROP DATABASE IF EXISTS 01759_db;
CREATE DATABASE 01759_db;
DROP TABLE IF EXISTS 01759_db.dictionary_source_table;
CREATE TABLE 01759_db.dictionary_source_table
(
key UInt64,
value1 UInt64,
value2 UInt64
)
ENGINE = TinyLog;
INSERT INTO 01759_db.dictionary_source_table VALUES (0, 2, 3), (1, 5, 6), (2, 8, 9);
DROP DICTIONARY IF EXISTS 01759_db.test_dictionary;
CREATE DICTIONARY 01759_db.test_dictionary(key UInt64, value1 UInt64, value1 UInt64)
PRIMARY KEY key
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'dictionary_source_table' DB '01759_db'))
LAYOUT(COMPLEX_KEY_DIRECT()); -- {serverError 36}
CREATE DICTIONARY 01759_db.test_dictionary(key UInt64, value1 UInt64, value2 UInt64)
PRIMARY KEY key
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'dictionary_source_table' DB '01759_db'))
LAYOUT(COMPLEX_KEY_DIRECT());
SELECT number, dictGet('01759_db.test_dictionary', 'value1', tuple(number)) as value1,
dictGet('01759_db.test_dictionary', 'value2', tuple(number)) as value2 FROM system.numbers LIMIT 3;
DROP TABLE 01759_db.dictionary_source_table;
DROP DATABASE 01759_db;