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 AVG groups accummulator ignoring return type #10114

Merged
merged 2 commits into from
Apr 18, 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
3 changes: 2 additions & 1 deletion datafusion/physical-expr/src/aggregate/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ where
// don't evaluate averages with null inputs to avoid errors on null values

let array: PrimitiveArray<T> = if nulls.null_count() > 0 {
let mut builder = PrimitiveBuilder::<T>::with_capacity(nulls.len());
let mut builder = PrimitiveBuilder::<T>::with_capacity(nulls.len())
.with_data_type(self.return_data_type.clone());
let iter = sums.into_iter().zip(counts).zip(nulls.iter());

for ((sum, count), is_valid) in iter {
Expand Down
10 changes: 5 additions & 5 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -2429,12 +2429,12 @@ statement ok
INSERT INTO test_decimal_table VALUES (1, 10.10, 100.1, NULL), (1, 20.20, 200.2, NULL), (2, 10.10, 700.1, NULL), (2, 20.20, 700.1, NULL), (3, 10.1, 100.1, NULL), (3, 10.1, NULL, NULL)

# aggregate_decimal_with_group_by
query IIRRRRIIR rowsort
select c1, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c3), count(c4), sum(c4) from test_decimal_table group by c1
query IIRRRRIIRR rowsort
select c1, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c3), count(c4), sum(c4), avg(c4) from test_decimal_table group by c1
----
1 2 15.15 30.3 10.1 20.2 2 0 NULL
2 2 15.15 30.3 10.1 20.2 2 0 NULL
3 2 10.1 20.2 10.1 10.1 1 0 NULL
1 2 15.15 30.3 10.1 20.2 2 0 NULL NULL
2 2 15.15 30.3 10.1 20.2 2 0 NULL NULL
3 2 10.1 20.2 10.1 10.1 1 0 NULL NULL

# aggregate_decimal_with_group_by_decimal
query RIRRRRIR rowsort
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sqllogictest/test_files/joins.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,7 @@ physical_plan
13)------------ProjectionExec: expr=[1 as c, 3 as d]
14)--------------PlaceholderRowExec

query IIII
query IIII rowsort
SELECT * FROM (
SELECT 1 as c, 2 as d
UNION ALL
Expand Down Expand Up @@ -3673,7 +3673,7 @@ physical_plan
11)------------ProjectionExec: expr=[1 as c, 3 as d]
12)--------------PlaceholderRowExec

query IIII
query IIII rowsort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we fixed them on main too with #10122 and #10120

SELECT * FROM (
SELECT 1 as c, 2 as d
UNION ALL
Expand Down