Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion be/src/vec/exprs/lambda_function/varray_map_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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<const DataTypeNullable*>(result_type.get())->get_nested_type();
} else {
nested_type = result_type;
}
auto empty_nested_column = assert_cast<const DataTypeArray*>(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();
}

MutableColumnPtr result_col = nullptr;
DataTypePtr res_type;
std::string res_name;
Expand Down Expand Up @@ -267,7 +300,6 @@ class ArrayMapFunction : public LambdaFunction {
} while (args_info.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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@
4 [[90, 100], [110, 120]]
5 [[130]]

-- !select_26 --
\N

-- !select_27 --
\N \N

-- !select_28 --
[]

Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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,
Expand All @@ -128,4 +129,46 @@ suite("test_array_map_function") {
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<TEXT> 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,[],[]); """
}
Loading