Column default dictGet identifier fix

This commit is contained in:
Maksim Kita 2021-09-10 17:41:09 +03:00
parent 43102e8427
commit a87ffdff92
3 changed files with 42 additions and 1 deletions

View File

@ -63,8 +63,11 @@ void addDefaultRequiredExpressionsRecursively(
for (const auto & next_required_column_name : required_columns_names)
addDefaultRequiredExpressionsRecursively(block, next_required_column_name, required_column_type, columns, default_expr_list_accum, added_columns, null_as_default);
}
else
else if (columns.has(required_column_name))
{
/// In case of dictGet function we allow to use it with identifier dictGet(identifier, 'column_name', key_expression)
/// and this identifier will be in required columns. If such column is not in ColumnsDescription we ignore it.
/// This column is required, but doesn't have default expression, so lets use "default default"
auto column = columns.get(required_column_name);
auto default_value = column.type->getDefault();

View File

@ -0,0 +1,37 @@
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table
(
key_column UInt64,
data_column_1 UInt64,
data_column_2 UInt8
)
ENGINE = MergeTree
ORDER BY key_column;
INSERT INTO test_table VALUES (0, 0, 0);
DROP DICTIONARY IF EXISTS test_dictionary;
CREATE DICTIONARY test_dictionary
(
key_column UInt64 DEFAULT 0,
data_column_1 UInt64 DEFAULT 1,
data_column_2 UInt8 DEFAULT 1
)
PRIMARY KEY key_column
LAYOUT(DIRECT())
SOURCE(CLICKHOUSE(TABLE 'test_table'));
DROP TABLE IF EXISTS test_table_default;
CREATE TABLE test_table_default
(
data_1 DEFAULT dictGetUInt64('test_dictionary', 'data_column_1', toUInt64(0)),
data_2 DEFAULT dictGet(test_dictionary, 'data_column_2', toUInt64(0))
)
ENGINE=TinyLog;
INSERT INTO test_table_default(data_1) VALUES (5);
SELECT * FROM test_table_default;
DROP DICTIONARY test_dictionary;
DROP TABLE test_table;
DROP TABLE test_table_default;