Skip to content

Commit

Permalink
Fix ApproxPercentileAccumulator on zero values (apache#9582)
Browse files Browse the repository at this point in the history
* Fix ApproxPercentileAccumulator

* Imports

* Use return type
  • Loading branch information
Dandandan authored Mar 13, 2024
1 parent 78bb64e commit 0302d65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -391,7 +391,7 @@ impl Accumulator for ApproxPercentileAccumulator {

fn evaluate(&mut self) -> Result<ScalarValue> {
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);

Expand Down
5 changes: 3 additions & 2 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0302d65

Please sign in to comment.