diff --git a/be/src/vec/aggregate_functions/aggregate_function_array_agg.h b/be/src/vec/aggregate_functions/aggregate_function_array_agg.h index 8c92b13a15aa50..86db5afec8fd57 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_array_agg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_array_agg.h @@ -128,15 +128,7 @@ struct AggregateFunctionArrayAggData { } void merge(const Self& rhs) { - const auto size = rhs.null_map->size(); - null_map->resize(size); - nested_column->reserve(size); - for (size_t i = 0; i < size; i++) { - const auto null_value = rhs.null_map->data()[i]; - const auto data_value = rhs.nested_column->get_data()[i]; - null_map->data()[i] = null_value; - nested_column->get_data().push_back(data_value); - } + column_data->insert_range_from(*rhs.column_data, 0, rhs.column_data->size()); } }; @@ -229,15 +221,7 @@ struct AggregateFunctionArrayAggData { } void merge(const Self& rhs) { - const auto size = rhs.null_map->size(); - null_map->resize(size); - nested_column->reserve(size); - for (size_t i = 0; i < size; i++) { - const auto null_value = rhs.null_map->data()[i]; - auto s = rhs.nested_column->get_data_at(i); - null_map->data()[i] = null_value; - nested_column->insert_data(s.data, s.size); - } + column_data->insert_range_from(*rhs.column_data, 0, rhs.column_data->size()); } }; diff --git a/be/src/vec/aggregate_functions/aggregate_function_foreachv2.cpp b/be/src/vec/aggregate_functions/aggregate_function_foreachv2.cpp index a4b87ff087e258..2ff8adc208f1f8 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_foreachv2.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_foreachv2.cpp @@ -85,7 +85,7 @@ void register_aggregate_function_combinator_foreachv2(AggregateFunctionSimpleFac for (const auto& t : types) { auto item_type = assert_cast(remove_nullable(t).get())->get_nested_type(); - transform_arguments.push_back((item_type)); + transform_arguments.push_back(item_type); } auto nested_function_name = name.substr(0, name.size() - suffix.size()); auto nested_function = factory.get(nested_function_name, transform_arguments, true, diff --git a/regression-test/data/function_p0/test_agg_foreach_multi_instance.out b/regression-test/data/function_p0/test_agg_foreach_multi_instance.out new file mode 100644 index 00000000000000..2ae7a10d2137d1 --- /dev/null +++ b/regression-test/data/function_p0/test_agg_foreach_multi_instance.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +[null, 1, 2, 2, 3, 20, 100] + +-- !sql -- +[null, "114514", "123", "ab", "c", "cd", "efg"] + diff --git a/regression-test/suites/function_p0/test_agg_foreach_multi_instance.groovy b/regression-test/suites/function_p0/test_agg_foreach_multi_instance.groovy new file mode 100644 index 00000000000000..fdbfb0cfbfccf1 --- /dev/null +++ b/regression-test/suites/function_p0/test_agg_foreach_multi_instance.groovy @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_agg_foreach_multi_instance") { + sql """ + drop table if exists foreach_table_m; + """ + + sql """ + CREATE TABLE IF NOT EXISTS foreach_table_m ( + `id` INT(11) null COMMENT "", + `a` array null COMMENT "", + `b` array> null COMMENT "", + `s` array null COMMENT "" + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ); + """ + sql """ + insert into foreach_table_m values + (1,[1,2,3],[[1],[1,2,3],[2]],["ab","123","114514"]), + (2,[20],[[2]],["cd"]), + (3,[100],[[1]],["efg"]) , + (4,null,[null],null), + (5,[null,2],[[2],null],[null,'c']); + """ + qt_sql """select array_sort(array_flatten(array_agg_foreach(a))) from foreach_table_m;""" + qt_sql """select array_sort(array_flatten(array_agg_foreach(s))) from foreach_table_m;""" +}