提交 9cc7d0f0 编写于 作者: A alesapin

Fix 'Cannot add column' error while creating range_hashed dictionary using DDL queries

上级 8be5a1f0
......@@ -75,16 +75,30 @@ NamesAndTypesList StorageDictionary::getNamesAndTypes(const DictionaryStructure
if (dictionary_structure.id)
dictionary_names_and_types.emplace_back(dictionary_structure.id->name, std::make_shared<DataTypeUInt64>());
/// In old-style (XML) configuration we don't have this attributes in the
/// main attribute list, so we have to add them to columns list explicitly.
/// In the new configuration (DDL) we have them both in range_* nodes and
/// main attribute list, but for compatibility we add them before main
/// attributes list.
if (dictionary_structure.range_min)
dictionary_names_and_types.emplace_back(dictionary_structure.range_min->name, dictionary_structure.range_min->type);
if (dictionary_structure.range_max)
dictionary_names_and_types.emplace_back(dictionary_structure.range_max->name, dictionary_structure.range_max->type);
if (dictionary_structure.key)
{
for (const auto & attribute : *dictionary_structure.key)
dictionary_names_and_types.emplace_back(attribute.name, attribute.type);
}
for (const auto & attribute : dictionary_structure.attributes)
dictionary_names_and_types.emplace_back(attribute.name, attribute.type);
{
/// Some attributes can be already added (range_min and range_max)
if (!dictionary_names_and_types.contains(attribute.name))
dictionary_names_and_types.emplace_back(attribute.name, attribute.type);
}
return dictionary_names_and_types;
}
......
DROP DATABASE IF EXISTS database_for_dict;
CREATE DATABASE database_for_dict;
use database_for_dict;
CREATE TABLE date_table
(
id UInt32,
val String,
start Date,
end Date
) Engine = Memory();
INSERT INTO date_table VALUES(1, '1', toDate('2019-01-05'), toDate('2020-01-10'));
CREATE DICTIONARY somedict
(
id UInt32,
val String,
start Date,
end Date
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'date_table' DB 'database_for_dict'))
LAYOUT(RANGE_HASHED())
RANGE (MIN start MAX end)
LIFETIME(MIN 300 MAX 360);
SELECT * from somedict;
SHOW TABLES;
DROP DATABASE IF EXISTS database_for_dict;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册