diff --git a/be/src/vec/exprs/lambda_function/varray_map_function.cpp b/be/src/vec/exprs/lambda_function/varray_map_function.cpp index 78a6ee8ac6..2d305af7b6 100644 --- a/be/src/vec/exprs/lambda_function/varray_map_function.cpp +++ b/be/src/vec/exprs/lambda_function/varray_map_function.cpp @@ -81,7 +81,7 @@ public: // offset column MutableColumnPtr array_column_offset; int nested_array_column_rows = 0; - + const ColumnArray::Offsets64* array_offsets = nullptr; //2. get the result column from executed expr, and the needed is nested column of array Block lambda_block; for (int i = 0; i < arguments.size(); ++i) { @@ -110,18 +110,25 @@ public: // here is the array column const ColumnArray& col_array = assert_cast(*column_array); const auto& col_type = assert_cast(*type_array); + if (i == 0) { nested_array_column_rows = col_array.get_data_ptr()->size(); + array_offsets = &col_array.get_offsets(); auto& off_data = assert_cast( col_array.get_offsets_column()); array_column_offset = off_data.clone_resized(col_array.get_offsets_column().size()); } else { // select array_map((x,y)->x+y,c_array1,[0,1,2,3]) from array_test2; // c_array1: [0,1,2,3,4,5,6,7,8,9] - if (nested_array_column_rows != col_array.get_data_ptr()->size()) { + if (nested_array_column_rows != col_array.get_data_ptr()->size() || + (array_offsets->size() > 0 && + memcmp(array_offsets->data(), col_array.get_offsets().data(), + sizeof((*array_offsets)[0]) * array_offsets->size()) != 0)) { return Status::InternalError( - "in array map function, the input column nested column data rows are " - "not equal, the first size is {}, but with {}th size is {}.", + "in array map function, the input column size " + "are " + "not equal completely, nested column data rows 1st size is {}, {}th " + "size is {}.", nested_array_column_rows, i + 1, col_array.get_data_ptr()->size()); } } diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_sortby.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_sortby.out index 5626b095cc..c4de582b93 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_sortby.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_sortby.out @@ -15,56 +15,56 @@ ['c', 'b', 'a'] -- !select_06 -- -0 \N [2] +0 [3] [2] 1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] 2 [6, 7, 8] [10, 12, 13] 3 [1] [-100] 4 \N \N -5 [3] \N +5 \N \N 6 [1, 2] [2, 1] 7 [NULL] [NULL] 8 [1, 2, 3] [3, 2, 1] -- !select_07 -- -0 \N [2] \N +0 [3] [2] [3] 1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] [5, 3, 1, 2, 4] 2 [6, 7, 8] [10, 12, 13] [6, 7, 8] 3 [1] [-100] [1] 4 \N \N \N -5 [3] \N [3] +5 \N \N \N 6 [1, 2] [2, 1] [2, 1] 7 [NULL] [NULL] [NULL] 8 [1, 2, 3] [3, 2, 1] [3, 2, 1] -- !select_08 -- -0 [2] \N [2] +0 [2] [3] [2] 1 [10, 20, -40, 80, -100] [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] 2 [10, 12, 13] [6, 7, 8] [10, 12, 13] 3 [-100] [1] [-100] 4 \N \N \N -5 \N [3] \N +5 \N \N \N 6 [2, 1] [1, 2] [2, 1] 7 [NULL] [NULL] [NULL] 8 [3, 2, 1] [1, 2, 3] [3, 2, 1] -- !select_09 -- -0 \N [2] \N \N -1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] [3, 12, 23, -36, 85] [4, 1, 2, 3, 5] -2 [6, 7, 8] [10, 12, 13] [-94, 17, 20] [6, 7, 8] -3 [1] [-100] [14] [1] +0 [3] [2] [5] [3] +1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] [11, 22, -37, 84, -95] [5, 3, 1, 2, 4] +2 [6, 7, 8] [10, 12, 13] [16, 19, 21] [6, 7, 8] +3 [1] [-100] [-99] [1] 4 \N \N \N \N -5 [3] \N \N [3] +5 \N \N \N \N 6 [1, 2] [2, 1] [3, 3] [1, 2] 7 [NULL] [NULL] [NULL] [NULL] 8 [1, 2, 3] [3, 2, 1] [4, 4, 4] [1, 2, 3] -- !select_10 -- -0 \N [2] \N \N -1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] [-1, -8, -17, 44, -75] [5, 3, 2, 1, 4] -2 [6, 7, 8] [10, 12, 13] [106, -3, -4] [8, 7, 6] -3 [1] [-100] [-12] [1] +0 [3] [2] [1] [3] +1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100] [-9, -18, 43, -76, 105] [4, 2, 1, 3, 5] +2 [6, 7, 8] [10, 12, 13] [-4, -5, -5] [7, 8, 6] +3 [1] [-100] [101] [1] 4 \N \N \N \N -5 [3] \N \N [3] +5 \N \N \N \N 6 [1, 2] [2, 1] [-1, 1] [1, 2] 7 [NULL] [NULL] [NULL] [NULL] 8 [1, 2, 3] [3, 2, 1] [-2, 0, 2] [1, 2, 3] diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_map_function.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_map_function.groovy index b5d4fbbe9d..4ba9b053bb 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_map_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_map_function.groovy @@ -71,5 +71,20 @@ suite("test_array_map_function") { qt_select_24 "select * from array_test2 order by array_max(array_map(x->x,c_array1));" + // Array not equal + sql """INSERT INTO ${tableName} values + (11, [6,7,8],[10,12,13]), + (12, [1,2,3], [10,20]), + (13, [2,3,4], [10,20,30,40]) + """ + + test { + sql"""select array_map((x,y)->x+y, c_array1, c_array2) from array_test2 where id > 10 order by id;""" + check{result, exception, startTime, endTime -> + assertTrue(exception != null) + logger.info(exception.message) + } + } + sql "DROP TABLE IF EXISTS ${tableName}" -} \ No newline at end of file +} diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_sortby.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_sortby.groovy index 0d2fe0f0b4..adcfac7f06 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_sortby.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_sortby.groovy @@ -35,10 +35,10 @@ suite("test_array_sortby") { sql """INSERT INTO ${tableName} values - (0,NULL,[2]), + (0,[3],[2]), (1, [1,2,3,4,5], [10,20,-40,80,-100]), (2, [6,7,8],[10,12,13]), (3, [1],[-100]), (4, null,null), - (5,[3],NULL),(6,[1,2],[2,1]),(7,[NULL],[NULL]),(8,[1,2,3],[3,2,1]) + (5,NULL,NULL),(6,[1,2],[2,1]),(7,[NULL],[NULL]),(8,[1,2,3],[3,2,1]) """ qt_select_00 " select array_sortby([1,2,3,4,5],[5,4,3,2,1]);" qt_select_01 " select array_sortby([1,2,3,4,5],NULL);"