diff --git a/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index 67d4e99cac6..c8b787ebd3f 100644 --- a/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -176,7 +176,7 @@ void buildSingleAttribute( AutoPtr null_value_element(doc->createElement("null_value")); String null_value_str; if (dict_attr->default_value) - null_value_str = queryToString(dict_attr->default_value); + null_value_str = getUnescapedFieldString(dict_attr->default_value->as()->value); AutoPtr null_value(doc->createTextNode(null_value_str)); null_value_element->appendChild(null_value); attribute_element->appendChild(null_value_element); @@ -184,7 +184,19 @@ void buildSingleAttribute( if (dict_attr->expression != nullptr) { AutoPtr expression_element(doc->createElement("expression")); - AutoPtr expression(doc->createTextNode(queryToString(dict_attr->expression))); + + /// Expression should be function or string + String expression_str; + if (const auto * literal = dict_attr->expression->as(); + literal && literal->value.getType() == Field::Types::String) + { + expression_str = getUnescapedFieldString(literal->value); + } + else + expression_str = queryToString(dict_attr->expression); + + + AutoPtr expression(doc->createTextNode(expression_str)); expression_element->appendChild(expression); attribute_element->appendChild(expression_element); } diff --git a/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.reference b/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.reference new file mode 100644 index 00000000000..0196135bda0 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.reference @@ -0,0 +1,4 @@ +hello +world +21844 +xxx diff --git a/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.sql b/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.sql new file mode 100644 index 00000000000..afd1c1c5780 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01043_dictionary_attribute_properties_values.sql @@ -0,0 +1,27 @@ +DROP DATABASE IF EXISTS dictdb; +CREATE DATABASE dictdb Engine = Ordinary; + +CREATE TABLE dictdb.dicttbl(key Int64, value_default String, value_expression String) ENGINE = MergeTree ORDER BY tuple(); +INSERT INTO dictdb.dicttbl VALUES (12, 'hello', '55:66:77'); + + +CREATE DICTIONARY dictdb.dict +( + key Int64 DEFAULT -1, + value_default String DEFAULT 'world', + value_expression String DEFAULT 'xxx' EXPRESSION 'toString(127 * 172)' + +) +PRIMARY KEY key +SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'dicttbl' DB 'dictdb')) +LAYOUT(FLAT()) +LIFETIME(1); + + +SELECT dictGetString('dictdb.dict', 'value_default', toUInt64(12)); +SELECT dictGetString('dictdb.dict', 'value_default', toUInt64(14)); + +SELECT dictGetString('dictdb.dict', 'value_expression', toUInt64(12)); +SELECT dictGetString('dictdb.dict', 'value_expression', toUInt64(14)); + +DROP DATABASE IF EXISTS dictdb;