kosiew commented on code in PR #17253:
URL: https://github.com/apache/datafusion/pull/17253#discussion_r2290196959
##########
datafusion/core/src/physical_planner.rs:
##########
@@ -1782,10 +1782,21 @@ pub fn create_aggregate_expr_and_maybe_filter(
physical_input_schema: &Schema,
execution_props: &ExecutionProps,
) -> Result<AggregateExprWithOptionalArgs> {
- // unpack (nested) aliased logical expressions, e.g. "sum(col) as total"
+ // Unpack (potentially nested) aliased logical expressions, e.g. "sum(col)
as total"
+ // Some functions like `count_all()` create internal aliases,
+ // Unwrap all alias layers to get to the underlying aggregate function
let (name, human_display, e) = match e {
Expr::Alias(Alias { expr, name, .. }) => {
- (Some(name.clone()), String::default(), expr.as_ref())
+ // Recursively unwrap nested aliases to reach the inner expression
+ let mut current_expr = expr.as_ref();
+ while let Expr::Alias(Alias { expr, .. }) = current_expr {
+ current_expr = expr.as_ref();
+ }
+ (
+ Some(name.clone()),
+ e.human_display().to_string(),
+ current_expr,
+ )
Review Comment:
You might leverage the existing Expr::unalias_nested helper to remove nested
aliases more idiomatically instead of manually traversing the AST.
--
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]