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 23050b6593c5ea..5f90827a70c5b8 100644 --- a/be/src/vec/exprs/lambda_function/varray_map_function.cpp +++ b/be/src/vec/exprs/lambda_function/varray_map_function.cpp @@ -192,6 +192,39 @@ class ArrayMapFunction : public LambdaFunction { data_types.push_back(col_type.get_nested_type()); } + ColumnWithTypeAndName result_arr; + // if column_array is NULL, we know the array_data_column will not write any data, + // so the column is empty. eg : (x) -> concat('|',x + "1"). if still execute the lambda function, will cause the bolck rows are not equal + // the x column is empty, but "|" is const literal, size of column is 1, so the block rows is 1, but the x column is empty, will be coredump. + if (std::any_of(lambda_datas.begin(), lambda_datas.end(), + [](const auto& v) { return v->empty(); })) { + DataTypePtr nested_type; + bool is_nullable = result_type->is_nullable(); + if (is_nullable) { + nested_type = + assert_cast(result_type.get())->get_nested_type(); + } else { + nested_type = result_type; + } + auto empty_nested_column = assert_cast(nested_type.get()) + ->get_nested_type() + ->create_column(); + auto result_array_column = ColumnArray::create(std::move(empty_nested_column), + std::move(array_column_offset)); + + if (is_nullable) { + result_arr = {ColumnNullable::create(std::move(result_array_column), + std::move(outside_null_map)), + result_type, "Result"}; + } else { + result_arr = {std::move(result_array_column), result_type, "Result"}; + } + + block->insert(result_arr); + *result_column_id = block->columns() - 1; + return Status::OK(); + } + ColumnPtr result_col = nullptr; DataTypePtr res_type; std::string res_name; @@ -260,7 +293,6 @@ class ArrayMapFunction : public LambdaFunction { } 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; if (result_type->is_nullable()) { if (res_type->is_nullable()) { 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 211092f3875215..0e3935d131fc4a 100644 --- 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 @@ -123,3 +123,12 @@ 4 [[90, 100], [110, 120]] 5 [[130]] +-- !select_26 -- +\N + +-- !select_27 -- +\N \N + +-- !select_28 -- +[] + 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 acf6dba0600411..fb67352a0d48d9 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,8 +103,8 @@ suite("test_array_map_function") { } sql "DROP TABLE IF EXISTS ${tableName}" + sql "DROP TABLE IF EXISTS array_map_test" -sql "DROP TABLE IF EXISTS array_map_test" sql """ CREATE TABLE IF NOT EXISTS array_map_test ( id INT, int_array ARRAY, @@ -129,4 +129,46 @@ sql "DROP TABLE IF EXISTS array_map_test" qt_select_25 """ SELECT id, array_map(x -> array_map(y -> y * 10, x), nested_array) FROM array_map_test order by id; """ + + sql "DROP TABLE IF EXISTS db" + + sql """ CREATE TABLE `db` ( + `id` VARCHAR(255) NULL COMMENT '主键', + `QC_result_list` ARRAY NULL COMMENT '标签预刷' + ) ENGINE=OLAP + UNIQUE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_medium" = "hdd", + "storage_format" = "V2", + "enable_unique_key_merge_on_write" = "true", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); + """ + + sql """insert into db values(1,null); + """ + + qt_select_26 """ + select array_map( + (x, y, z) -> concat( + '|', + x + "1", + '|', + x + "2", + '|', + x + "3" + ), + QC_result_list, + QC_result_list, + QC_result_list + ) FROM db; + """ + + qt_select_27 """ select QC_result_list, array_map( x -> concat( '|', x + "1" ), QC_result_list ) FROM db; """ + qt_select_28 """ select array_map((x,y)->x,[],[]); """ }