Skip to content

Commit 58c7085

Browse files
authored
Fix: approx_percentile_cont_with_weight Panic (#12823)
* Fixed NaN Error * fmt fix * Added guard * Remove checks
1 parent e0b807b commit 58c7085

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

datafusion/functions-aggregate-common/src/tdigest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ impl TDigest {
644644
let max = cast_scalar_f64!(&state[3]);
645645
let min = cast_scalar_f64!(&state[4]);
646646

647-
assert!(max.total_cmp(&min).is_ge());
647+
if min.is_finite() && max.is_finite() {
648+
assert!(max.total_cmp(&min).is_ge());
649+
}
648650

649651
Self {
650652
max_size,

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,24 @@ NaN
13851385
statement ok
13861386
DROP TABLE tmp_percentile_cont;
13871387

1388+
# Test for issue where approx_percentile_cont_with_weight
1389+
1390+
statement ok
1391+
CREATE TABLE t1(v1 BOOL);
1392+
1393+
statement ok
1394+
INSERT INTO t1 VALUES (TRUE);
1395+
1396+
# ISSUE: https://github.com/apache/datafusion/issues/12716
1397+
# This test verifies that approx_percentile_cont_with_weight does not panic when given 'NaN' and returns 'inf'
1398+
query R
1399+
SELECT approx_percentile_cont_with_weight('NaN'::DOUBLE, 0, 0) FROM t1 WHERE t1.v1;
1400+
----
1401+
Infinity
1402+
1403+
statement ok
1404+
DROP TABLE t1;
1405+
13881406
# csv_query_cube_avg
13891407
query TIR
13901408
SELECT c1, c2, AVG(c3) FROM aggregate_test_100 GROUP BY CUBE (c1, c2) ORDER BY c1, c2

0 commit comments

Comments
 (0)