DictionaryStructure fix non unique attribute names

This commit is contained in:
Maksim Kita 2021-03-12 16:36:42 +03:00
parent 2e7f756d7c
commit 97a58777b8
3 changed files with 44 additions and 0 deletions

View File

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