Skip to content

Commit 61e6db3

Browse files
authored
Fix panic in variance GroupsAccumulator (#12615)
The bug was in the orginal implementation in #12095. This fixes the issue and modify a test case such that it would have caught it.
1 parent b821929 commit 61e6db3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

datafusion/functions-aggregate/src/variance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl VarianceGroupsAccumulator {
470470

471471
if let StatsType::Sample = self.stats_type {
472472
counts.iter_mut().for_each(|count| {
473-
*count -= 1;
473+
*count = count.saturating_sub(1);
474474
});
475475
}
476476
let nulls = NullBuffer::from_iter(counts.iter().map(|&count| count != 0));

datafusion/sqllogictest/test_files/aggregate.slt

+4-4
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,13 @@ set datafusion.sql_parser.dialect = 'Postgres';
567567

568568
# csv_query_stddev_12
569569
query IR
570-
SELECT c2, var_samp(c12) FILTER (WHERE c12 > 0.90) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2
570+
SELECT c2, var_samp(c12) FILTER (WHERE c12 > 0.95) FROM aggregate_test_100 GROUP BY c2 ORDER BY c2
571571
----
572-
1 0.000889240174
573-
2 0.000785878272
572+
1 0.000791243479
573+
2 0.000061521903
574574
3 NULL
575575
4 NULL
576-
5 0.000269544643
576+
5 NULL
577577

578578
# Restore the default dialect
579579
statement ok

0 commit comments

Comments
 (0)