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


##########
datafusion/functions-aggregate/src/percentile_cont.rs:
##########
@@ -297,76 +212,71 @@ impl AggregateUDFImpl for PercentileCont {
         ])
     }
 
-    fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn 
Accumulator>> {
-        self.create_accumulator(&acc_args)
+    fn accumulator(&self, args: AccumulatorArgs) -> Result<Box<dyn 
Accumulator>> {
+        let percentile = get_percentile(&args)?;
+
+        let input_dt = args.expr_fields[0].data_type();
+        if input_dt.is_null() {
+            return 
Ok(Box::new(NoopAccumulator::new(ScalarValue::Float64(None))));
+        }
+
+        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}"),
+            }
+        }
     }
 
     fn groups_accumulator_supported(&self, args: AccumulatorArgs) -> bool {
-        !args.is_distinct
+        !args.is_distinct && !args.expr_fields[0].data_type().is_null()
     }
 
     fn create_groups_accumulator(
         &self,
         args: AccumulatorArgs,
     ) -> Result<Box<dyn GroupsAccumulator>> {
-        let num_args = args.exprs.len();
-        assert_eq_or_internal_err!(
-            num_args,
-            2,
-            "percentile_cont should have 2 args, but found num args:{}",
-            num_args
-        );
-
-        let percentile = validate_percentile_expr(&args.exprs[1], 
"PERCENTILE_CONT")?;
+        let percentile = get_percentile(&args)?;

Review Comment:
   For simplicity I made `groups_accumulator_supported` return false if we have 
a null datatype input



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