diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h b/be/src/vec/functions/function_date_or_datetime_computation.h index b45333b89d..dd25e0fca9 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -452,8 +452,8 @@ struct DateTimeAddIntervalImpl { const auto is_nullable = block.get_by_position(result).type->is_nullable(); if (const auto* sources = check_and_get_column>(source_col.get())) { auto col_to = ColumnVector::create(); - const IColumn& delta_column = - *remove_nullable(block.get_by_position(arguments[1]).column); + auto delta_column_ptr = remove_nullable(block.get_by_position(arguments[1]).column); + const IColumn& delta_column = *delta_column_ptr; if (is_nullable) { auto null_map = ColumnUInt8::create(input_rows_count, 0); @@ -545,16 +545,17 @@ struct DateTimeAddIntervalImpl { auto col_to = ColumnVector::create(); if (is_nullable) { auto null_map = ColumnUInt8::create(input_rows_count, 0); + auto not_nullable_column_ptr_arg1 = + remove_nullable(block.get_by_position(arguments[1]).column); if (const auto* delta_vec_column = check_and_get_column>( - *remove_nullable(block.get_by_position(arguments[1]).column))) { + *not_nullable_column_ptr_arg1)) { Op::constant_vector(sources_const->template get_value(), col_to->get_data(), null_map->get_data(), delta_vec_column->get_data()); } else { - Op::constant_vector( - sources_const->template get_value(), col_to->get_data(), - null_map->get_data(), - *remove_nullable(block.get_by_position(arguments[1]).column)); + Op::constant_vector(sources_const->template get_value(), + col_to->get_data(), null_map->get_data(), + *not_nullable_column_ptr_arg1); } if (const auto* nullable_col = check_and_get_column( block.get_by_position(arguments[0]).column.get())) { diff --git a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out index a08ba6294f..fe55f5432e 100644 --- a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out +++ b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out @@ -590,6 +590,9 @@ true -- !sql -- 2019-08-01T13:21:02.111111 +-- !sql -- +-1096 + -- !sql -- \N \N \N \N 2000-02-29 2000-02-29 2000-02-29 2000-02-29 diff --git a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy index 83f99991a8..c88de59acc 100644 --- a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy @@ -548,6 +548,8 @@ suite("test_date_function") { qt_sql """ select minutes_sub(test_time2,1) result from ${tableName}; """ //seconds_sub qt_sql """ select seconds_sub(test_time2,1) result from ${tableName}; """ + //datediff + qt_sql """ select datediff(test_time2, STR_TO_DATE('2022-08-01 00:00:00','%Y-%m-%d')) from ${tableName}; """ // test last_day for vec sql """ DROP TABLE IF EXISTS ${tableName}; """