diff --git a/datafusion/functions-aggregate-common/src/tdigest.rs b/datafusion/functions-aggregate-common/src/tdigest.rs index 620a68e83ecd..e6723b54b372 100644 --- a/datafusion/functions-aggregate-common/src/tdigest.rs +++ b/datafusion/functions-aggregate-common/src/tdigest.rs @@ -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, diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 250fa85cddef..54ce91b8e71b 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -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