mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Fix an unexpected behavior in #53152
The problematic case happens when an array column of date/datetime is simultaneously specified in an Array Join clause without aliases and in a time converter, such as toYYYYMM. After applying Array Join without aliases, the column's name refers to the flattened array items, however, its data type is recognized as a ColumnArray still, which leads to the unexpected exception throws when building the preimage for the time converters. As a quick fix, we more strictly check the data types of the time converters and quit the preimage optimization pass early.
This commit is contained in:
parent
aae35f3b1c
commit
3579039733
@ -160,15 +160,18 @@ void OptimizeDateOrDateTimeConverterWithPreimageMatcher::visit(const ASTFunction
|
||||
auto data_type_and_name = data.tables[*pos].columns.tryGetByName(column_id->shortName());
|
||||
if (!data_type_and_name) return;
|
||||
|
||||
const auto column_type = data_type_and_name->type;
|
||||
if (!column_type || (!isDateOrDate32(*column_type) && !isDateTime(*column_type) && !isDateTime64(*column_type))) return;
|
||||
|
||||
const auto & converter = FunctionFactory::instance().tryGet(ast_func->name, data.context);
|
||||
if (!converter) return;
|
||||
|
||||
ColumnsWithTypeAndName args;
|
||||
args.emplace_back(data_type_and_name->type, "tmp");
|
||||
args.emplace_back(column_type, "tmp");
|
||||
auto converter_base = converter->build(args);
|
||||
if (!converter_base || !converter_base->hasInformationAboutPreimage()) return;
|
||||
|
||||
auto preimage_range = converter_base->getPreimage(*(data_type_and_name->type), literal->value);
|
||||
auto preimage_range = converter_base->getPreimage(*column_type, literal->value);
|
||||
if (!preimage_range) return;
|
||||
|
||||
const auto new_ast = generateOptimizedDateFilterAST(comparator, *data_type_and_name, *preimage_range);
|
||||
|
@ -0,0 +1,2 @@
|
||||
202308 1
|
||||
202308 2
|
@ -0,0 +1,9 @@
|
||||
select
|
||||
toYYYYMM(date) as date_,
|
||||
n
|
||||
from (select
|
||||
[toDate('20230815'), toDate('20230816')] as date,
|
||||
[1, 2] as n
|
||||
) as data
|
||||
array join date, n
|
||||
where date_ >= 202303;
|
Loading…
Reference in New Issue
Block a user