[fix](if) fix coredump of if const (#14858)
This commit is contained in:
@ -455,6 +455,19 @@ public:
|
||||
cond_column.column = materialize_column_if_const(cond_column.column);
|
||||
const ColumnWithTypeAndName& arg_cond = block.get_by_position(arguments[0]);
|
||||
|
||||
if (auto* then_is_const = check_and_get_column<ColumnConst>(*arg_then.column)) {
|
||||
if (check_and_get_column<ColumnNullable>(then_is_const->get_data_column())) {
|
||||
ColumnWithTypeAndName& then_column = block.get_by_position(arguments[1]);
|
||||
then_column.column = materialize_column_if_const(then_column.column);
|
||||
}
|
||||
}
|
||||
if (auto* else_is_const = check_and_get_column<ColumnConst>(*arg_else.column)) {
|
||||
if (check_and_get_column<ColumnNullable>(else_is_const->get_data_column())) {
|
||||
ColumnWithTypeAndName& else_column = block.get_by_position(arguments[2]);
|
||||
else_column.column = materialize_column_if_const(else_column.column);
|
||||
}
|
||||
}
|
||||
|
||||
Status ret = Status::OK();
|
||||
if (execute_for_null_condition(context, block, arg_cond, arg_then, arg_else, result) ||
|
||||
execute_for_null_then_else(context, block, arg_cond, arg_then, arg_else, result,
|
||||
|
||||
@ -191,3 +191,14 @@ true
|
||||
999
|
||||
999
|
||||
|
||||
-- !if_true_then_nullable --
|
||||
4
|
||||
|
||||
-- !if_true_else_nullable --
|
||||
2
|
||||
|
||||
-- !if_false_then_nullable --
|
||||
2
|
||||
|
||||
-- !if_false_else_nullable --
|
||||
4
|
||||
|
||||
@ -87,5 +87,11 @@ suite("test_conditional_function") {
|
||||
|
||||
qt_sql "select ifnull( user_id, 999) r from ${tbName} order by r"
|
||||
|
||||
qt_if_true_then_nullable """select IF(true, DAYOFWEEK("2022-12-06 17:48:46"), 1) + 1;"""
|
||||
qt_if_true_else_nullable """select IF(true, 1, DAYOFWEEK("2022-12-06 17:48:46")) + 1;"""
|
||||
|
||||
qt_if_false_then_nullable """select IF(false, DAYOFWEEK("2022-12-06 17:48:46"), 1) + 1;"""
|
||||
qt_if_false_else_nullable """select IF(false, 1, DAYOFWEEK("2022-12-06 17:48:46")) + 1;"""
|
||||
|
||||
sql "DROP TABLE ${tbName};"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user