Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX](array_agg) fix array agg with other agg function #32387

Merged
merged 2 commits into from
Mar 19, 2024
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
14 changes: 7 additions & 7 deletions be/src/vec/aggregate_functions/aggregate_function_collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ struct AggregateFunctionArrayAggData<StringRef> {
void deserialize_and_merge(const IColumn& column, size_t row_num) {
auto& to_arr = assert_cast<const ColumnArray&>(column);
auto& to_nested_col = to_arr.get_data();
auto col_null = reinterpret_cast<const ColumnNullable*>(&to_nested_col);
auto col_null = assert_cast<const ColumnNullable*>(&to_nested_col);
const auto& vec = assert_cast<const ColVecType&>(col_null->get_nested_column());
auto start = to_arr.get_offsets()[row_num - 1];
auto end = start + to_arr.get_offsets()[row_num] - to_arr.get_offsets()[row_num - 1];
Expand Down Expand Up @@ -556,8 +556,8 @@ class AggregateFunctionCollect
const size_t num_rows) const override {
if constexpr (ShowNull::value) {
for (size_t i = 0; i != num_rows; ++i) {
this->data(places[i]).deserialize_and_merge(*assert_cast<const IColumn*>(column),
i);
this->data(places[i] + offset)
.deserialize_and_merge(*assert_cast<const IColumn*>(column), i);
}
} else {
return BaseHelper::deserialize_and_merge_vec(places, offset, rhs, column, arena,
Expand Down Expand Up @@ -596,9 +596,9 @@ class AggregateFunctionCollect
Arena* arena, const size_t num_rows) const override {
if constexpr (ShowNull::value) {
for (size_t i = 0; i != num_rows; ++i) {
if (places[i]) {
this->data(places[i]).deserialize_and_merge(
*assert_cast<const IColumn*>(column), i);
if (places[i] + offset) {
this->data(places[i] + offset)
.deserialize_and_merge(*assert_cast<const IColumn*>(column), i);
}
}
} else {
Expand Down Expand Up @@ -671,4 +671,4 @@ class AggregateFunctionCollect
using IAggregateFunction::argument_types;
};

} // namespace doris::vectorized
} // namespace doris::vectorized
84 changes: 57 additions & 27 deletions regression-test/data/query_p0/aggregate/array_agg.out
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql1 --
["LC", "LB", "alex"]
["LC", "LB", "LA"]
["LC", null, "LA"]
["LC", "LB", "LA"]
[null, "LC", "LB", "LA"]
[null, "LC", "LC", "LC", "LC"]
[null, "LC", "LC", "LC", "LC"]
3 ["LC", "LB", "LA"]
3 ["LC", "LB", "LA"]
3 ["LC", "LB", "alex"]
3 ["LC", null, "LA"]
4 [null, "LC", "LB", "LA"]
5 [null, "LC", "LC", "LC", "LC"]
5 [null, "LC", "LC", "LC", "LC"]

-- !sql2 --
["alex", null, "LC", "LC", "LC", "LC"]
["LB"]
["LC"]
["LA"]
["LB"]
["LC"]
["LA"]
["LC"]
["LA"]
["LB"]
["LC"]
["LA"]
["LB"]
[null, "LC"]
[null, "LC", "LC"]
[null, "LC", "LC"]
0 ["alex", null, "LC", "LC", "LC", "LC"]
1 ["LA"]
1 ["LA"]
1 ["LA"]
1 ["LA"]
1 ["LB"]
1 ["LB"]
1 ["LB"]
1 ["LB"]
1 ["LC"]
1 ["LC"]
1 ["LC"]
1 ["LC"]
2 [null, "LC"]
3 [null, "LC", "LC"]
3 [null, "LC", "LC"]

-- !sql3 --
["LC", "LB", "alex", "LC", "LB", "LA", "LC", null, "LA", "LC", "LB", "LA", null, "LC", "LB", "LA", null, "LC", "LC", "LC", "LC", null, "LC", "LC", "LC", "LC"]
Expand All @@ -44,14 +44,17 @@
-- !sql6 --
[""]

-- !sql6_1 --
\N [""]

-- !sql7 --
["LC", "LB", "alex"]
[""]
[""]
["LC", "LB", "LA"]
["LC", null, "LA"]
["LC", "LB", "LA"]
["LC", "LB", "LA"]
[""]
[""]
["LC", "LB", "alex"]
["LC", null, "LA"]

-- !sql8 --
[null]
Expand All @@ -65,3 +68,30 @@
7 [null]
8 [null]

-- !sql11 --
3 3
3 3
3 3
3 3
4 4
5 5
5 5

-- !sql21 --
0 6
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 2
3 3
3 3

84 changes: 73 additions & 11 deletions regression-test/suites/query_p0/aggregate/array_agg.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

suite("array_agg") {
sql "DROP TABLE IF EXISTS `test_array_agg`;"
sql "DROP TABLE IF EXISTS `test_array_agg1`;"
sql "DROP TABLE IF EXISTS `test_array_agg_int`;"
sql "DROP TABLE IF EXISTS `test_array_agg_decimal`;"
sql """
Expand Down Expand Up @@ -157,39 +158,100 @@ suite("array_agg") {
(8, "", NULL,0,NULL,"alexcoco2");
"""

qt_sql1 """
SELECT array_agg(`label_name`) FROM `test_array_agg` GROUP BY `id` order by id;
order_qt_sql1 """
SELECT count(id), array_agg(`label_name`) FROM `test_array_agg` GROUP BY `id` order by id;
"""
qt_sql2 """
SELECT array_agg(label_name) FROM `test_array_agg` GROUP BY value_field order by value_field;
order_qt_sql2 """
SELECT count(value_field), array_agg(label_name) FROM `test_array_agg` GROUP BY value_field order by value_field;
"""
qt_sql3 """
order_qt_sql3 """
SELECT array_agg(`label_name`) FROM `test_array_agg`;
"""
qt_sql4 """
order_qt_sql4 """
SELECT array_agg(`value_field`) FROM `test_array_agg`;
"""
qt_sql5 """
order_qt_sql5 """
SELECT id, array_agg(age) FROM test_array_agg_int GROUP BY id order by id;
"""

qt_sql6 """
order_qt_sql6 """
select array_agg(label_name) from test_array_agg_decimal where id=7;
"""

qt_sql7 """
order_qt_sql6_1 """
select sum(o_totalprice), array_agg(label_name) from test_array_agg_decimal where id=7;
"""

order_qt_sql7 """
select array_agg(label_name) from test_array_agg_decimal group by id order by id;
"""

qt_sql8 """
order_qt_sql8 """
select array_agg(age) from test_array_agg_decimal where id=7;
"""

qt_sql9 """
order_qt_sql9 """
select id,array_agg(o_totalprice) from test_array_agg_decimal group by id order by id;
"""


// test for bucket 10
sql """ CREATE TABLE `test_array_agg1` (
`id` int(11) NOT NULL,
`label_name` varchar(32) default null,
`value_field` string default null
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false"
); """

sql """
insert into `test_array_agg1` values
(1, "alex",NULL),
(1, "LB", "V1_2"),
(1, "LC", "V1_3"),
(2, "LA", "V2_1"),
(2, "LB", "V2_2"),
(2, "LC", "V2_3"),
(3, "LA", "V3_1"),
(3, NULL, NULL),
(3, "LC", "V3_3"),
(4, "LA", "V4_1"),
(4, "LB", "V4_2"),
(4, "LC", "V4_3"),
(5, "LA", "V5_1"),
(5, "LB", "V5_2"),
(5, "LC", "V5_3"),
(5, NULL, "V5_3"),
(6, "LC", "V6_3"),
(6, "LC", NULL),
(6, "LC", "V6_3"),
(6, "LC", NULL),
(6, NULL, "V6_3"),
(7, "LC", "V7_3"),
(7, "LC", NULL),
(7, "LC", "V7_3"),
(7, "LC", NULL),
(7, NULL, "V7_3");
"""

order_qt_sql11 """
SELECT count(id), size(array_agg(`label_name`)) FROM `test_array_agg` GROUP BY `id` order by id;
"""
order_qt_sql21 """
SELECT count(value_field), size(array_agg(label_name)) FROM `test_array_agg` GROUP BY value_field order by value_field;
"""


sql "DROP TABLE `test_array_agg`"
sql "DROP TABLE `test_array_agg1`"
sql "DROP TABLE `test_array_agg_int`"
sql "DROP TABLE `test_array_agg_decimal`"
}
Loading