Skip to content

Commit

Permalink
Fix: approx_percentile_cont_with_weight Panic (apache#12823)
Browse files Browse the repository at this point in the history
* Fixed NaN Error

* fmt fix

* Added guard

* Remove checks
  • Loading branch information
jonathanc-n authored Oct 10, 2024
1 parent e0b807b commit 58c7085
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion datafusion/functions-aggregate-common/src/tdigest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ impl TDigest {
let max = cast_scalar_f64!(&state[3]);
let min = cast_scalar_f64!(&state[4]);

assert!(max.total_cmp(&min).is_ge());
if min.is_finite() && max.is_finite() {
assert!(max.total_cmp(&min).is_ge());
}

Self {
max_size,
Expand Down
18 changes: 18 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,24 @@ NaN
statement ok
DROP TABLE tmp_percentile_cont;

# Test for issue where approx_percentile_cont_with_weight

statement ok
CREATE TABLE t1(v1 BOOL);

statement ok
INSERT INTO t1 VALUES (TRUE);

# ISSUE: https://github.com/apache/datafusion/issues/12716
# This test verifies that approx_percentile_cont_with_weight does not panic when given 'NaN' and returns 'inf'
query R
SELECT approx_percentile_cont_with_weight('NaN'::DOUBLE, 0, 0) FROM t1 WHERE t1.v1;
----
Infinity

statement ok
DROP TABLE t1;

# csv_query_cube_avg
query TIR
SELECT c1, c2, AVG(c3) FROM aggregate_test_100 GROUP BY CUBE (c1, c2) ORDER BY c1, c2
Expand Down

0 comments on commit 58c7085

Please sign in to comment.