jayzhan211 commented on PR #11229: URL: https://github.com/apache/datafusion/pull/11229#issuecomment-2207580822
> @jayzhan211 thanks for the feedback. I like the idea because it would seem to avoid having to update the count function to accept zero args. The current approach is nice at least in that it's very clear what's happening (at least to me) and while a bit of code it's mostly a single chunk. > > Can you say more about new planner trait and how that'd be used? Is the idea I'd implement `UserDefinedSQLPlanner` for a new struct like `CountPlanner`? > > Also, since this is somewhat inspired from duckdb, they do a `count_star()` function that is distinct from other counts and is an alias for `count()`. This approach may be nice in that it'd afford the opportunity to have a dataframe expression itself and also wouldn't require updating the args for `count`. I think we can have a more general Planner, AggregateFunctionPlanner ``` if let Some(fm) = self.context_provider.get_aggregate_meta(&name) { let order_by = self.order_by_to_sort_expr( &order_by, schema, planner_context, true, None, )?; let order_by = (!order_by.is_empty()).then_some(order_by); let args = self.function_args_to_expr(args, schema, planner_context)?; let filter: Option<Box<Expr>> = filter .map(|e| self.sql_expr_to_logical_expr(*e, schema, planner_context)) .transpose()? .map(Box::new); let raw_aggregate_function = RawAggregateFunction { fm, args, distinct, filter, order_by, null_treatment, } // general planner for rewriting aggregate function // we convert wildcard and empty args to lit(1) for count in our case plan_aggregate_function(raw_aggregate_function) return Ok(Expr::AggregateFunction(expr::AggregateFunction::new_udf( fm, args, distinct, filter, order_by, null_treatment, ))); } ``` https://github.com/apache/datafusion/blob/fe66daaa81738dc60afc297a79897faaaa127724/datafusion/sql/src/expr/function.rs#L337-L359 -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org