Simple key dictionary primary key wrong order fix

This commit is contained in:
Maksim Kita 2021-04-18 15:19:44 +03:00
parent 8b3c37e648
commit b26dfcd514
3 changed files with 41 additions and 1 deletions

View File

@ -307,7 +307,22 @@ void buildPrimaryKeyConfiguration(
AutoPtr<Element> name_element(doc->createElement("name"));
id_element->appendChild(name_element);
const ASTDictionaryAttributeDeclaration * dict_attr = children.front()->as<const ASTDictionaryAttributeDeclaration>();
auto identifier_name = key_names.front();
auto it = std::find_if(children.begin(), children.end(), [&](const ASTPtr & node)
{
const ASTDictionaryAttributeDeclaration * dict_attr = node->as<const ASTDictionaryAttributeDeclaration>();
return dict_attr->name == identifier_name;
});
if (it == children.end())
{
throw Exception(ErrorCodes::INCORRECT_DICTIONARY_DEFINITION,
"Primary key field '{}' not found among attributes",
identifier_name);
}
const ASTDictionaryAttributeDeclaration * dict_attr = (*it)->as<const ASTDictionaryAttributeDeclaration>();
AutoPtr<Text> name(doc->createTextNode(dict_attr->name));
name_element->appendChild(name);

View File

@ -0,0 +1,24 @@
DROP TABLE IF EXISTS dictionary_primary_key_source_table;
CREATE TABLE dictionary_primary_key_source_table
(
identifier UInt64,
v UInt64
) ENGINE = TinyLog;
INSERT INTO dictionary_primary_key_source_table VALUES (20, 1);
DROP DICTIONARY IF EXISTS flat_dictionary;
CREATE DICTIONARY flat_dictionary
(
identifier UInt64,
v UInt64
)
PRIMARY KEY v
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_primary_key_source_table'))
LIFETIME(MIN 1 MAX 1000)
LAYOUT(FLAT());
SELECT * FROM flat_dictionary;
DROP DICTIONARY flat_dictionary;
DROP TABLE dictionary_primary_key_source_table;