From 21c3a116a65494af4c4a064c70031928baf28d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Heres?= Date: Tue, 12 Mar 2024 16:19:18 +0100 Subject: [PATCH] Fix ApproxPercentileAccumulator --- .../physical-expr/src/aggregate/approx_percentile_cont.rs | 2 +- datafusion/sqllogictest/test_files/aggregate.slt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs b/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs index b3de7b0b4d36..2e90afbeeb8b 100644 --- a/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs +++ b/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs @@ -391,7 +391,7 @@ impl Accumulator for ApproxPercentileAccumulator { fn evaluate(&mut self) -> Result { if self.digest.count() == 0.0 { - return exec_err!("aggregate function needs at least one non-null element"); + return Ok(ScalarValue::Null); } let q = self.digest.estimate_quantile(self.percentile); diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 09dd62803e3f..19bcf6024b50 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -2255,9 +2255,10 @@ select median(a) from (select 1 as a where 1=0); ---- NULL -query error DataFusion error: Execution error: aggregate function needs at least one non-null element +query I select approx_median(a) from (select 1 as a where 1=0); - +---- +NULL # aggregate_decimal_sum query RT