Jefffrey commented on PR #21453:
URL: https://github.com/apache/datafusion/pull/21453#issuecomment-4272957460

   I was thinking along the lines of utilizing 
[`simplify`](https://docs.rs/datafusion/latest/datafusion/logical_expr/trait.AggregateUDFImpl.html#method.simplify)
 on `approx_distinct`, like:
   
   ```rust
       fn simplify(&self) -> Option<AggregateFunctionSimplification> {
           Some(Box::new(|aggregate_function, info| {
               let input_type = 
info.get_data_type(&aggregate_function.params.args[0])?;
               match input_type {
                   DataType::UInt8 | DataType::Int8 | DataType::UInt16 | 
DataType::Int16 => {
                       let rewritten = 
Expr::AggregateFunction(AggregateFunction::new_udf(
                           count_udaf(),
                           aggregate_function.params.args,
                           aggregate_function.params.distinct,
                           aggregate_function.params.filter,
                           aggregate_function.params.order_by,
                           aggregate_function.params.null_treatment,
                       ));
                       Ok(rewritten)
                   }
                   _ => Ok(Expr::AggregateFunction(aggregate_function)),
               }
           }))
       }
   ```
   
   Which can avoid the need of a wrapper. Also for the boolean accumulator we 
could make regular count distinct use that too and include boolean type as part 
of the simplify call 🤔 


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