mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix escaping and add string expressions support
This commit is contained in:
parent
39bb8e724c
commit
642ce2d751
@ -176,7 +176,7 @@ void buildSingleAttribute(
|
||||
AutoPtr<Element> 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<ASTLiteral>()->value);
|
||||
AutoPtr<Text> 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<Element> expression_element(doc->createElement("expression"));
|
||||
AutoPtr<Text> expression(doc->createTextNode(queryToString(dict_attr->expression)));
|
||||
|
||||
/// Expression should be function or string
|
||||
String expression_str;
|
||||
if (const auto * literal = dict_attr->expression->as<ASTLiteral>();
|
||||
literal && literal->value.getType() == Field::Types::String)
|
||||
{
|
||||
expression_str = getUnescapedFieldString(literal->value);
|
||||
}
|
||||
else
|
||||
expression_str = queryToString(dict_attr->expression);
|
||||
|
||||
|
||||
AutoPtr<Text> expression(doc->createTextNode(expression_str));
|
||||
expression_element->appendChild(expression);
|
||||
attribute_element->appendChild(expression_element);
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
hello
|
||||
world
|
||||
21844
|
||||
xxx
|
@ -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;
|
Loading…
Reference in New Issue
Block a user