fix nullable issue, range hash setting and strengthen test

This commit is contained in:
jsc0218 2023-12-28 16:16:06 +00:00
parent fd9a2a6417
commit 17f391abb8
7 changed files with 51 additions and 5 deletions

View File

@ -249,7 +249,7 @@ ColumnPtr FlatDictionary::getColumnOrDefaultShortCircuit(
callOnDictionaryAttributeType(attribute.type, type_call);
if (attribute.is_nullable_set)
result = ColumnNullable::create(result, std::move(col_null_map_to));
result = ColumnNullable::create(result, col_null_map_to->filter(default_mask, found_count));
return result;
}

View File

@ -885,7 +885,7 @@ ColumnPtr HashedArrayDictionary<dictionary_key_type, sharded>::getAttributeColum
callOnDictionaryAttributeType(attribute.type, type_call);
if (is_attribute_nullable)
result = ColumnNullable::create(result, std::move(col_null_map_to));
result = ColumnNullable::create(result, col_null_map_to->filter(default_mask, found_count));
return result;
}

View File

@ -592,7 +592,7 @@ ColumnPtr HashedDictionary<dictionary_key_type, sparse, sharded>::getColumnOrDef
callOnDictionaryAttributeType(attribute.type, type_call);
if (is_attribute_nullable)
result = ColumnNullable::create(result, std::move(col_null_map_to));
result = ColumnNullable::create(result, col_null_map_to->filter(default_mask, found_count));
return result;
}

View File

@ -470,6 +470,7 @@ public:
const auto & column_before_cast = arguments[current_arguments_index];
const auto * column_function = checkAndGetShortCircuitArgument(column_before_cast.column);
/// If we have shortcircuit (column_function exists), default_cols is empty.
if (!column_function)
{
ColumnWithTypeAndName column_to_cast = {column_before_cast.column->convertToFullColumnIfConst(), column_before_cast.type, column_before_cast.name};

View File

@ -190,8 +190,8 @@ static void setLazyExecutionInfo(
lazy_execution_info.can_be_lazy_executed = false;
}
/// Currently only used in dictGetOrDefault.
if (parent->children.size() == 4 && node == parent->children[2] &&
/// Currently only used in dictGetOrDefault. RANGE_HASHED dictionary has 5 arguments instead of 4.
if (parent->children.size() > 3 && node == parent->children[2] &&
!short_circuit_nodes.at(parent).enable_lazy_execution_for_third_argument)
{
/// We shouldn't add 2 index in node info in this case.

View File

@ -1,9 +1,15 @@
Flat dictionary
('zero','zero')
('zero','zero')
\N
\N
Hashed dictionary
('zero','zero')
('zero','zero')
\N
\N
Hashed array dictionary
('zero','zero')
('zero','zero')
\N
\N

View File

@ -25,6 +25,8 @@ LAYOUT(FLAT());
SELECT 'Flat dictionary';
SELECT dictGetOrDefault('flat_dictionary', ('v1', 'v2'), 0, (intDiv(1, id), intDiv(1, id)))
FROM dictionary_source_table;
SELECT dictGetOrDefault('flat_dictionary', 'v2', id+1, intDiv(NULL, id))
FROM dictionary_source_table;
DROP DICTIONARY flat_dictionary;
@ -43,6 +45,8 @@ LAYOUT(HASHED());
SELECT 'Hashed dictionary';
SELECT dictGetOrDefault('hashed_dictionary', ('v1', 'v2'), 0, (intDiv(1, id), intDiv(1, id)))
FROM dictionary_source_table;
SELECT dictGetOrDefault('hashed_dictionary', 'v2', id+1, intDiv(NULL, id))
FROM dictionary_source_table;
DROP DICTIONARY hashed_dictionary;
@ -61,7 +65,42 @@ LAYOUT(HASHED_ARRAY());
SELECT 'Hashed array dictionary';
SELECT dictGetOrDefault('hashed_array_dictionary', ('v1', 'v2'), 0, (intDiv(1, id), intDiv(1, id)))
FROM dictionary_source_table;
SELECT dictGetOrDefault('hashed_array_dictionary', 'v2', id+1, intDiv(NULL, id))
FROM dictionary_source_table;
DROP DICTIONARY hashed_array_dictionary;
-- DROP TABLE IF EXISTS range_dictionary_source_table;
-- CREATE TABLE range_dictionary_source_table
-- (
-- id UInt64,
-- start Date,
-- end Nullable(Date),
-- val UInt64
-- ) ENGINE=TinyLog;
-- INSERT INTO range_dictionary_source_table VALUES (0, '2023-01-01', Null, 0), (1, '2023-12-26', '2023-12-27', 1);
-- DROP DICTIONARY IF EXISTS range_hashed_dictionary;
-- CREATE DICTIONARY range_hashed_dictionary
-- (
-- id UInt64,
-- start Date,
-- end Nullable(Date),
-- val UInt64
-- )
-- PRIMARY KEY id
-- SOURCE(CLICKHOUSE(TABLE 'range_dictionary_source_table'))
-- LIFETIME(MIN 0 MAX 0)
-- LAYOUT(RANGE_HASHED())
-- RANGE(MIN start MAX end);
-- SELECT 'Range hashed dictionary';
-- SELECT dictGetOrDefault('range_hashed_dictionary', 'val', id, toDate('2023-01-02'), toDate('1933-01-22'))
-- FROM range_dictionary_source_table;
-- DROP DICTIONARY range_hashed_dictionary;
-- DROP TABLE range_dictionary_source_table;
DROP TABLE dictionary_source_table;