From 13c999f7af0538da71198389ae3cdfa753ba00ee Mon Sep 17 00:00:00 2001 From: amorynan Date: Thu, 27 Jun 2024 17:50:02 +0800 Subject: [PATCH] fix array set with left param which is const column --- be/src/vec/functions/array/function_array_set.h | 6 +++++- .../array_functions/test_array_functions.out | 12 ++++++++++++ .../array_functions/test_array_functions.groovy | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/be/src/vec/functions/array/function_array_set.h b/be/src/vec/functions/array/function_array_set.h index 41bf53f921f3fb..8a7959b53dffd2 100644 --- a/be/src/vec/functions/array/function_array_set.h +++ b/be/src/vec/functions/array/function_array_set.h @@ -181,7 +181,11 @@ struct ArraySetImpl { constexpr auto execute_left_column_first = Impl::Action::execute_left_column_first; size_t current = 0; Impl impl; - for (size_t row = 0; row < left_data.offsets_ptr->size(); ++row) { + size_t row_size = left_data.offsets_ptr->size(); + if constexpr (LCONST) { + row_size = right_data.offsets_ptr->size(); + } + for (size_t row = 0; row < row_size; ++row) { size_t count = 0; size_t left_off = (*left_data.offsets_ptr)[index_check_const(row, LCONST) - 1]; size_t left_len = (*left_data.offsets_ptr)[index_check_const(row, LCONST)] - left_off; diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out index 1b60f4270583ca..664ea154982602 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out @@ -1659,14 +1659,26 @@ 10005 [10005, null, null] [null, 3, 10005, 2, 1] 10006 [60002, 60002, 60003, null, 60005] [null, 3, 60002, 60005, 60003, 2, 1] +-- !select_union_left_const -- +10005 [10005, null, null] [null, 3, 10005, 2, 1] +10006 [60002, 60002, 60003, null, 60005] [null, 3, 60002, 60005, 60003, 2, 1] + -- !select_except -- 10005 [10005, null, null] [10005, null] 10006 [60002, 60002, 60003, null, 60005] [60002, 60003, null, 60005] +-- !select_except_left_const -- +10005 [10005, null, null] [1, 2, 3] +10006 [60002, 60002, 60003, null, 60005] [1, 2, 3] + -- !select_intersect -- 10005 [10005, null, null] [null] 10006 [60002, 60002, 60003, null, 60005] [null] +-- !select_intersect_left_const -- +10005 [10005, null, null] [null] +10006 [60002, 60002, 60003, null, 60005] [null] + -- !select_array_datetimev2_1 -- 1 ["2023-01-19 18:11:11.111", "2023-01-19 18:22:22.222", "2023-01-19 18:33:33.333"] ["2023-01-19 18:22:22.222", "2023-01-19 18:33:33.333", "2023-01-19 18:44:44.444"] ["2023-01-19 18:11:11.111111", "2023-01-19 18:22:22.222222", "2023-01-19 18:33:33.333333"] diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy index c043ada07af502..f278483e707bff 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy @@ -273,8 +273,11 @@ suite("test_array_functions") { sql """ insert into ${tableName3} values (10006,'bbbbb',[60002,60002,60003,null,60005]) """ qt_select_union "select class_id, student_ids, array_union(student_ids,[1,2,3]) from ${tableName3} order by class_id;" + qt_select_union_left_const "select class_id, student_ids, array_union([1,2,3], student_ids,[1,2,3]) from ${tableName3} order by class_id;" qt_select_except "select class_id, student_ids, array_except(student_ids,[1,2,3]) from ${tableName3} order by class_id;" + qt_select_except_left_const "select class_id, student_ids, array_except([1,2,3], student_ids) from ${tableName3} order by class_id;" qt_select_intersect "select class_id, student_ids, array_intersect(student_ids,[1,2,3,null]) from ${tableName3} order by class_id;" + qt_select_intersect_left_const "select class_id, student_ids, array_intersect([1,2,3,null], student_ids) from ${tableName3} order by class_id;" def tableName4 = "tbl_test_array_datetimev2_functions"