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


##########
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:
   yep that would be good to fix, ideally our udfs should align to their 
declared signatures



-- 
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