You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "GaneshPatil7517 (via GitHub)" <gi...@apache.org> on 2026/01/07 21:21:49 UTC

[PR] Fix: Show aliased aggregate expressions in physical EXPLAIN output [datafusion]

GaneshPatil7517 opened a new pull request, #19693:
URL: https://github.com/apache/datafusion/pull/19693

   ## Which issue does this PR close?
   
   Closes #19685
   
   ## Rationale for this change
   
   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 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?
   
   1. **`datafusion/core/src/physical_planner.rs`**: Modified `create_aggregate_expr_and_maybe_filter()` to use the unaliased expression for `human_display`, so it captures the actual aggregate expression instead of just the alias name.
   
   2. **`datafusion/physical-plan/src/aggregates/mod.rs`**: Modified `DisplayAs` impl for `AggregateExec` to show both the expression (`human_display`) and alias (`name()`) when they differ, in the format `{expression} as {alias}`.
   
   3. **Test file updates**: Updated test expectations in `explain.slt`, `aggregate.slt`, and `agg_func_substitute.slt` to reflect the new output format.
   
   ## Are these changes tested?
   
   Yes. Added new test cases in `explain.slt` that specifically verify aliased aggregate expressions are visible in physical EXPLAIN output. Updated existing test expectations in `aggregate.slt` and `agg_func_substitute.slt`.
   
   ## Are there any user-facing changes?
   
   Yes. The physical plan `EXPLAIN` output now shows the full aggregate expression along with its alias when they differ, improving plan readability and debuggability.


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix: Show aliased aggregate expressions in physical EXPLAIN output [datafusion]

Posted by "GaneshPatil7517 (via GitHub)" <gi...@apache.org>.
GaneshPatil7517 closed pull request #19693: Fix: Show aliased aggregate expressions in physical EXPLAIN output
URL: https://github.com/apache/datafusion/pull/19693


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix: Show aliased aggregate expressions in physical EXPLAIN output [datafusion]

Posted by "GaneshPatil7517 (via GitHub)" <gi...@apache.org>.
GaneshPatil7517 commented on code in PR #19693:
URL: https://github.com/apache/datafusion/pull/19693#discussion_r2676806041


##########
docs/source/library-user-guide/functions/udf-nullability.md:
##########


Review Comment:
   I apologize for the confusion il fix it...



-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix: Show aliased aggregate expressions in physical EXPLAIN output [datafusion]

Posted by "GaneshPatil7517 (via GitHub)" <gi...@apache.org>.
GaneshPatil7517 commented on code in PR #19693:
URL: https://github.com/apache/datafusion/pull/19693#discussion_r2676806041


##########
docs/source/library-user-guide/functions/udf-nullability.md:
##########


Review Comment:
   Apologies for the confusion! I accidentally created the branch from the wrong base.



-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix: Show aliased aggregate expressions in physical EXPLAIN output [datafusion]

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #19693:
URL: https://github.com/apache/datafusion/pull/19693#discussion_r2676622205


##########
datafusion/expr/src/udaf.rs:
##########


Review Comment:
   same: these changes don't seem to belong to this PR or I am missing the connection of the PR title to the reasoning.



##########
docs/source/library-user-guide/functions/adding-udfs.md:
##########
@@ -1350,6 +1350,12 @@ async fn main() -> Result<()> {
 [`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

Review Comment:
   same



##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -1126,6 +1126,102 @@ ORDER BY tags, timestamp;
 4 tag2 90 75 80 95
 5 tag2 100 80 80 100
 
+###########

Review Comment:
   doesn't belong to this PR?



##########
docs/source/library-user-guide/functions/udf-nullability.md:
##########


Review Comment:
   same



##########
datafusion/functions-aggregate/src/percentile_cont.rs:
##########


Review Comment:
   same



##########
datafusion/expr-common/src/accumulator.rs:
##########


Review Comment:
   why are these changes included in this PR?



##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -8246,3 +8342,44 @@ query R
 select percentile_cont(null, 0.5);
 ----
 NULL
+

Review Comment:
   also doesn't belong here?



##########
datafusion/core/src/physical_planner.rs:
##########
@@ -2189,7 +2189,11 @@ pub fn create_aggregate_expr_and_maybe_filter(
     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)

Review Comment:
   this seems to be the core change that also matches the PR title



##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -1083,7 +1083,16 @@ impl DisplayAs for AggregateExec {
                 let a: Vec<String> = self
                     .aggr_expr
                     .iter()
-                    .map(|agg| agg.name().to_string())

Review Comment:
   this change makes sense



-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org