Skip to content
Closed
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
32 changes: 31 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 @@ -139,6 +139,36 @@ class ArrayMapFunction : public LambdaFunction {
lambda_block.insert(std::move(data_column));
}

ColumnWithTypeAndName result_arr;
if (std::any_of(lambda_block.begin(), lambda_block.end(), [](const auto& v) {
DCHECK(v.column != nullptr);
return v.column->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(std::move(result_arr));
*result_column_id = block->columns() - 1;
return Status::OK();
}
//3. child[0]->execute(new_block)
RETURN_IF_ERROR(children[0]->execute(context, &lambda_block, result_column_id));

Expand All @@ -148,7 +178,7 @@ class ArrayMapFunction : public LambdaFunction {
auto res_name = lambda_block.get_by_position(*result_column_id).name;

//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 = {ColumnNullable::create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@
1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100]
2 [6, 7, 8] [10, 12, 13]

-- !select_26 --
\N

-- !select_27 --
\N \N

-- !select_28 --
[]

Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,46 @@ suite("test_array_map_function") {
}

sql "DROP TABLE IF EXISTS ${tableName}"

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->x,[]); """
}
Loading