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
12 changes: 12 additions & 0 deletions be/src/exprs/function/function_string_concat.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ class FunctionStringConcatWs : public IFunction {
std::vector<std::string_view> views;

if (is_column<ColumnArray>(argument_columns[1].get())) {
if (argument_size != 2) {
return Status::InvalidArgument(
"concat_ws with array argument expects exactly 2 arguments, but got {}",
argument_size);
}
// Determine if the nested type of the array is String
const auto& array_column = reinterpret_cast<const ColumnArray&>(*argument_columns[1]);
if (!array_column.get_data().is_column_string()) {
Expand Down Expand Up @@ -472,6 +477,7 @@ class FunctionStringConcatWs : public IFunction {
const auto& src_string_offsets = string_column.get_offsets();
const auto& src_array_offsets = array_column.get_offsets();
size_t current_src_array_offset = 0;
auto& array_nullmap = *null_list[1];

// Concat string in array
for (size_t i = 0; i < input_rows_count; ++i) {
Expand All @@ -485,6 +491,12 @@ class FunctionStringConcatWs : public IFunction {
continue;
}

if (array_nullmap[i]) {
StringOP::push_empty_string(i, res_data, res_offset);
current_src_array_offset += src_array_offsets[i] - src_array_offsets[i - 1];
continue;
}

int sep_size = sep_offsets[i] - sep_offsets[i - 1];
const char* sep_data = reinterpret_cast<const char*>(&sep_chars[sep_offsets[i - 1]]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ a-b-css-d
x-y-z
你好-世界-Doris-Nereids

-- !concat_ws_array_null_full --
1 [] 0
2 [a,b,c] 5

-- !concat_ws_array_null_filter --
1 [] 0

Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ suite("nereids_scalar_fn_concat_ws") {
sql "INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])"
qt_concat_ws_insert_1 "SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id"

}
sql "DROP TABLE IF EXISTS test_concat_ws_array_null"
sql "CREATE TABLE test_concat_ws_array_null (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>, c ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1')"
sql "INSERT INTO test_concat_ws_array_null VALUES (1, ['a'], NULL, ['b']), (2, ['a'], ['b'], ['c'])"
qt_concat_ws_array_null_full "SELECT id, CONCAT('[', CONCAT_WS(',', a, b, c), ']'), LENGTH(CONCAT_WS(',', a, b, c)) FROM test_concat_ws_array_null ORDER BY id"
qt_concat_ws_array_null_filter "SELECT id, CONCAT('[', CONCAT_WS(',', a, b, c), ']'), LENGTH(CONCAT_WS(',', a, b, c)) FROM test_concat_ws_array_null WHERE id = 1"

sql "SET disable_nereids_expression_rules = 'CONCATWS_MULTI_ARRAY_TO_ONE'"
test {
sql "SELECT CONCAT_WS(',', a, b, c) FROM test_concat_ws_array_null ORDER BY id"
exception "concat_ws with array argument expects exactly 2 arguments"
}
sql "SET disable_nereids_expression_rules = ''"

}
Loading