diff --git a/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs b/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs index b3de7b0b4d36..3dbf1679e230 100644 --- a/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs +++ b/datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs @@ -30,8 +30,8 @@ use arrow::{ use arrow_array::RecordBatch; use arrow_schema::Schema; use datafusion_common::{ - downcast_value, exec_err, internal_err, not_impl_err, plan_err, DataFusionError, - Result, ScalarValue, + downcast_value, internal_err, not_impl_err, plan_err, DataFusionError, Result, + ScalarValue, }; use datafusion_expr::{Accumulator, ColumnarValue}; use std::{any::Any, iter, sync::Arc}; @@ -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 ScalarValue::try_from(self.return_type.clone()); } 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