-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix: Show aliased aggregate expressions in physical EXPLAIN output #19693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Show aliased aggregate expressions in physical EXPLAIN output #19693
Conversation
crepererum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either I am misunderstanding the PR, or it is misnamed, or it accidentally includes a bunch of unrelated changes
| let (name, human_display, e) = match e { | ||
| Expr::Alias(Alias { name, .. }) => { | ||
| let unaliased = e.clone().unalias_nested().data; | ||
| (Some(name.clone()), e.human_display().to_string(), unaliased) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be the core change that also matches the PR title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these changes included in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same: these changes don't seem to belong to this PR or I am missing the connection of the PR title to the reasoning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| let a: Vec<String> = self | ||
| .aggr_expr | ||
| .iter() | ||
| .map(|agg| agg.name().to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change makes sense
| 4 tag2 90 75 80 95 | ||
| 5 tag2 100 80 80 100 | ||
|
|
||
| ########### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't belong to this PR?
| select percentile_cont(null, 0.5); | ||
| ---- | ||
| NULL | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also doesn't belong here?
| [`create_udaf`]: https://docs.rs/datafusion/latest/datafusion/logical_expr/fn.create_udaf.html | ||
| [`advanced_udaf.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udaf.rs | ||
|
|
||
| ### Nullability of Aggregate Functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the confusion! I accidentally created the branch from the wrong base.
…pache#19685) When an aggregate expression has been aliased, the logical plan EXPLAIN shows both the alias and the original expression. However, the physical plan EXPLAIN only showed the alias, making plans hard to interpret. This fix updates the physical EXPLAIN output to show both the underlying aggregate expression and its alias in the format: AggregateExec: mode=Single, gby=[], aggr=[sum(column1@0) as my_alias] instead of: AggregateExec: mode=Single, gby=[], aggr=[my_alias] Changes: - Modified create_aggregate_expr_and_maybe_filter() in physical_planner.rs to use the unaliased expression for human_display, so it captures the actual aggregate expression instead of just the alias name. - Modified DisplayAs impl for AggregateExec to show both expression and alias when they differ. - Updated test expectations in explain.slt, aggregate.slt, and agg_func_substitute.slt to reflect the new output format.
eeb1ede to
4ef18bd
Compare
Which issue does this PR close?
Closes #19685
Rationale for this change
When an aggregate expression has been aliased, the logical plan
EXPLAINshows both the alias and the original expression. However, the physical planEXPLAINonly showed the alias name, making plans hard to interpret.Before:
AggregateExec: mode=Single, gby=[], aggr=[agg]
AggregateExec: mode=Single, gby=[], aggr=[sum(column1@0) FILTER (WHERE column2@1 <= Int64(0)) as agg]
What changes are included in this PR?
datafusion/core/src/physical_planner.rs: Modifiedcreate_aggregate_expr_and_maybe_filter()to use the unaliased expression forhuman_display, so it captures the actual aggregate expression instead of just the alias name.datafusion/physical-plan/src/aggregates/mod.rs: ModifiedDisplayAsimpl forAggregateExecto show both the expression (human_display) and alias (name()) when they differ, in the format{expression} as {alias}.Test file updates: Updated test expectations in
explain.slt,aggregate.slt, andagg_func_substitute.sltto reflect the new output format.Are these changes tested?
Yes. Added new test cases in
explain.sltthat specifically verify aliased aggregate expressions are visible in physical EXPLAIN output. Updated existing test expectations inaggregate.sltandagg_func_substitute.slt.Are there any user-facing changes?
Yes. The physical plan
EXPLAINoutput now shows the full aggregate expression along with its alias when they differ, improving plan readability and debuggability.