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: Panic/correctness issue in variance GroupsAccumulator #12615

Merged
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
2 changes: 1 addition & 1 deletion datafusion/functions-aggregate/src/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl VarianceGroupsAccumulator {

if let StatsType::Sample = self.stats_type {
counts.iter_mut().for_each(|count| {
*count -= 1;
*count = count.saturating_sub(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return error if count is already 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think producing null is the expected behavior. Note that we use the counts to calculate the null array after this.

});
}
let nulls = NullBuffer::from_iter(counts.iter().map(|&count| count != 0));
Expand Down
8 changes: 4 additions & 4 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,13 @@ set datafusion.sql_parser.dialect = 'Postgres';

# csv_query_stddev_12
query IR
SELECT c2, var_samp(c12) FILTER (WHERE c12 > 0.90) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2
SELECT c2, var_samp(c12) FILTER (WHERE c12 > 0.95) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2
----
1 0.000889240174
2 0.000785878272
1 0.000791243479
2 0.000061521903
3 NULL
4 NULL
5 0.000269544643
5 NULL

# Restore the default dialect
statement ok
Expand Down