theirix commented on code in PR #24419:
URL: https://github.com/apache/datafusion/pull/24419#discussion_r3808147489


##########
datafusion/functions-aggregate/src/percentile_cont.rs:
##########
@@ -216,39 +218,43 @@ impl AggregateUDFImpl for PercentileCont {
     }
 
     fn accumulator(&self, args: AccumulatorArgs) -> Result<Box<dyn 
Accumulator>> {
-        let percentile = get_percentile(&args)?;
-
         let input_dt = args.expr_fields[0].data_type();
+        // Null input evaluates to null
         if input_dt.is_null() {
-            return 
Ok(Box::new(NoopAccumulator::new(ScalarValue::Float64(None))));
+            return Ok(Box::new(NoopAccumulator::default()));
         }
 
-        if args.is_distinct {
-            match input_dt {
-                DataType::Float16 => 
Ok(Box::new(DistinctPercentileContAccumulator::<
-                    Float16Type,
-                >::new(percentile))),
-                DataType::Float32 => 
Ok(Box::new(DistinctPercentileContAccumulator::<
-                    Float32Type,
-                >::new(percentile))),
-                DataType::Float64 => 
Ok(Box::new(DistinctPercentileContAccumulator::<
-                    Float64Type,
-                >::new(percentile))),
-                dt => internal_err!("Unsupported datatype for percentile cont: 
{dt}"),
-            }
-        } else {
-            match input_dt {
-                DataType::Float16 => Ok(Box::new(
-                    PercentileContAccumulator::<Float16Type>::new(percentile),
-                )),
-                DataType::Float32 => Ok(Box::new(
-                    PercentileContAccumulator::<Float32Type>::new(percentile),
-                )),
-                DataType::Float64 => Ok(Box::new(
-                    PercentileContAccumulator::<Float64Type>::new(percentile),
-                )),
-                dt => internal_err!("Unsupported datatype for percentile cont: 
{dt}"),
-            }
+        macro_rules! helper {
+            ($t:ty, $i:ty, $dt:expr) => {
+                if args.is_distinct {
+                    Ok(Box::new(DistinctPercentileContAccumulator::<$t, 
$i>::new(
+                        get_percentile(&args)?,
+                        $dt.clone(),
+                    )))
+                } else {
+                    Ok(Box::new(PercentileContAccumulator::<$t, $i>::new(
+                        get_percentile(&args)?,
+                        $dt.clone(),
+                    )))
+                }
+            };
+        }
+        macro_rules! integer_helper {
+            ($t:ty, $dt:expr) => {
+                helper!($t, IntegerInterpolator, $dt)
+            };
+        }
+
+        downcast_integer! {
+            input_dt => (integer_helper, input_dt),

Review Comment:
   Not via sql since we don't have integer signatures.
   
   It's reached from  [this `test_oom` 
test](https://github.com/apache/datafusion/blob/f6ad7810d05748bac745f677eee575b3d06ba50e/datafusion/physical-plan/src/aggregates/mod.rs#L3888)
 because it passes integer types explicitly, without coercion to floats.
   
   ---- aggregates::tests::test_oom stdout ----
   Error: Internal("Unsupported datatype for percentile cont: 
UInt32\n\nbacktrace:    0: 
<datafusion_functions_aggregate::percentile_cont::PercentileCont as 
datafusion_expr::udaf::AggregateUDFImpl>::accumulator\n   1: 
<datafusion_functions_aggregate::median::Median as 
datafusion_expr::udaf::AggregateUDFImpl>::accumulator\n   2: 
<datafusion_expr::udaf::AggregateUDF>::accumulator\n   3: 
<datafusion_physical_expr::aggregate::AggregateFunctionExpr>::create_accumulator\n
   4: datafusion_physical_plan::aggregates::create_accumulators::{closure#0}\n  
 5: 
core::iter::adapters::map::map_try_fold::<&alloc::sync::Arc<datafusion_physical_expr::aggregate::AggregateFunctionExpr>,
 core::result::Result<alloc::boxed::Box<dyn 
datafusion_expr_common::accumulator::Accumulator>, 
datafusion_common::error::DataFusionError>, (), 
core::ops::control_flow::ControlFlow<core::ops::control_flow::ControlFlow<alloc::boxed::Box<dyn
 datafusion_expr_common::accumulator::Accumulator>>>, 
   
   Integers should be coerced to floats (rechecked with DuckDB/Postgres). It's 
better to rewrite that test to properly pass floats and remove semi-dead 
integer handling entirely.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to