Jefffrey commented on code in PR #24419:
URL: https://github.com/apache/datafusion/pull/24419#discussion_r3800306232
##########
datafusion/functions-aggregate/src/median.rs:
##########
@@ -91,6 +68,7 @@ make_udaf_expr_and_func!(
#[derive(PartialEq, Eq, Hash, Debug)]
pub struct Median {
signature: Signature,
+ percentile_cont: PercentileCont,
Review Comment:
i do wonder if we should implement `simplify` for median to make it an
unconditional rewrite to percentile_cont
##########
datafusion/functions-aggregate/src/percentile_cont.rs:
##########
@@ -143,18 +134,32 @@ impl Default for PercentileCont {
impl PercentileCont {
pub fn new() -> Self {
Self {
- signature: Signature::coercible(
+ signature: Signature::one_of(
vec![
- Coercion::new_implicit(
- TypeSignatureClass::Float,
- vec![TypeSignatureClass::Numeric],
- NativeType::Float64,
- ),
- Coercion::new_implicit(
- TypeSignatureClass::Native(logical_float64()),
- vec![TypeSignatureClass::Numeric],
- NativeType::Float64,
- ),
+ // Decimal signature: decimals, percentile
+ TypeSignature::Coercible(vec![
+ // value
+ Coercion::new_exact(TypeSignatureClass::Decimal),
+ // percentile
+ Coercion::new_implicit(
+ TypeSignatureClass::Native(logical_float64()),
+ vec![TypeSignatureClass::Numeric],
+ NativeType::Float64,
+ ),
Review Comment:
```suggestion
Coercion::new_implicit_native(
logical_float64(),
vec![TypeSignatureClass::Numeric],
),
```
- new simpler API from https://github.com/apache/datafusion/pull/24282
##########
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:
are integer types supported in the signature? is this code being reached?
##########
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)?;
Review Comment:
i think its intentional to check the percentile up here, so that we still
error on invalid percentiles even if input is null
--
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]