This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new fbad523a13c [cherry-pick](branch-21) pick (#50913) (#51072) fbad523a13c is described below commit fbad523a13cd3826de158dee23d17c2e219cbc81 Author: zhangstar333 <zhangs...@selectdb.com> AuthorDate: Thu May 22 14:34:29 2025 +0800 [cherry-pick](branch-21) pick (#50913) (#51072) ### What problem does this PR solve? Problem Summary: pick from master (#50913) ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into --> --- .../exprs/lambda_function/varray_map_function.cpp | 17 +++++++------- .../array_functions/test_array_map_function.out | Bin 2417 -> 2522 bytes .../array_functions/test_array_map_function.groovy | 26 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) 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 78b7c6cf68c..04938b2b8c9 100644 --- a/be/src/vec/exprs/lambda_function/varray_map_function.cpp +++ b/be/src/vec/exprs/lambda_function/varray_map_function.cpp @@ -158,20 +158,20 @@ public: } // here is the array column - const ColumnArray& col_array = assert_cast<const ColumnArray&>(*column_array); + const auto& col_array = assert_cast<const ColumnArray&>(*column_array); const auto& col_type = assert_cast<const DataTypeArray&>(*type_array); if (i == 0) { nested_array_column_rows = col_array.get_data_ptr()->size(); first_array_offsets = col_array.get_offsets_ptr(); - auto& off_data = assert_cast<const ColumnArray::ColumnOffsets&>( + const auto& off_data = assert_cast<const ColumnArray::ColumnOffsets&>( col_array.get_offsets_column()); array_column_offset = off_data.clone_resized(col_array.get_offsets_column().size()); args.offsets_ptr = &col_array.get_offsets(); } 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] - auto& array_offsets = + const auto& array_offsets = assert_cast<const ColumnArray::ColumnOffsets&>(*first_array_offsets) .get_data(); if (nested_array_column_rows != col_array.get_data_ptr()->size() || @@ -197,9 +197,10 @@ public: //process first row args.array_start = (*args.offsets_ptr)[args.current_row_idx - 1]; - args.cur_size = (*args.offsets_ptr)[args.current_row_idx] - args.array_start; - - while (args.current_row_idx < block->rows()) { + args.cur_size = (*args.offsets_ptr).size() + ? (*args.offsets_ptr)[args.current_row_idx] - args.array_start + : 0; + do { Block lambda_block; for (int i = 0; i < names.size(); i++) { ColumnWithTypeAndName data_column; @@ -219,7 +220,7 @@ public: long current_step = std::min(max_step, (long)(args.cur_size - args.current_offset_in_array)); size_t pos = args.array_start + args.current_offset_in_array; - for (int i = 0; i < arguments.size(); ++i) { + for (int i = 0; i < arguments.size() && current_step > 0; ++i) { columns[gap + i]->insert_range_from(*lambda_datas[i], pos, current_step); } args.current_offset_in_array += current_step; @@ -255,7 +256,7 @@ public: MutableColumnPtr column = (*std::move(result_col)).mutate(); column->insert_range_from(*res_col, 0, res_col->size()); } - } + } while (args.current_row_idx < block->rows()); //4. get the result column after execution, reassemble it into a new array column, and return. ColumnWithTypeAndName result_arr; diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_map_function.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_map_function.out index 39649ca512e..211092f3875 100644 Binary files a/regression-test/data/query_p0/sql_functions/array_functions/test_array_map_function.out and b/regression-test/data/query_p0/sql_functions/array_functions/test_array_map_function.out differ 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 17de93942bf..bc786d2da71 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 @@ -103,4 +103,30 @@ suite("test_array_map_function") { } sql "DROP TABLE IF EXISTS ${tableName}" + + sql "DROP TABLE IF EXISTS array_map_test" + sql """ CREATE TABLE IF NOT EXISTS array_map_test ( + id INT, + int_array ARRAY<INT>, + string_array ARRAY<STRING>, + double_array ARRAY<DOUBLE>, + nested_array ARRAY<ARRAY<INT>>, + nullable_array ARRAY<INT> NULL + ) ENGINE=OLAP + DUPLICATE KEY(id) + DISTRIBUTED BY HASH(id) BUCKETS 10 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ INSERT INTO array_map_test VALUES + (1, [1,2,3], ['a','b','c'], [1.1,2.2,3.3], [[1,2],[3,4]], NULL), + (2, [10,20], ['x','y'], [10.5,20.5], [[5,6],[7,8]], [1,2,3]), + (3, [], [], [], [], []), + (4, [100,200,300], ['one','two','three'], [100.1,200.2,300.3], [[9,10],[11,12]], [4,5,6]), + (5, [5], ['single'], [5.5], [[13]], [7]); + """ + qt_select_25 """ + SELECT id, array_map(x -> array_map(y -> y * 10, x), nested_array) FROM array_map_test order by id; + """ } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org