You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "zebsme (via GitHub)" <gi...@apache.org> on 2025/03/09 06:26:02 UTC
[PR] Implement tree explain for AggregateExec [datafusion]
zebsme opened a new pull request, #15103:
URL: https://github.com/apache/datafusion/pull/15103
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Close #15024
- Part of #14914
## What changes are included in this PR?
1. Implement AggregateExec
2. Update related tests
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
3. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#discussion_r1986382181
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -809,8 +809,54 @@ impl DisplayAs for AggregateExec {
}
}
DisplayFormatType::TreeRender => {
- // TODO: collect info
- write!(f, "")?;
+ let g: Vec<String> = if self.group_by.is_single() {
Review Comment:
Thanks @zebsme !
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#discussion_r1986313731
##########
datafusion/sqllogictest/test_files/explain_tree.slt:
##########
@@ -124,25 +124,39 @@ logical_plan
physical_plan
01)┌───────────────────────────┐
02)│ AggregateExec │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│ CoalesceBatchesExec │
-06)└─────────────┬─────────────┘
-07)┌─────────────┴─────────────┐
-08)│ RepartitionExec │
-09)└─────────────┬─────────────┘
-10)┌─────────────┴─────────────┐
-11)│ AggregateExec │
-12)└─────────────┬─────────────┘
-13)┌─────────────┴─────────────┐
-14)│ RepartitionExec │
-15)└─────────────┬─────────────┘
-16)┌─────────────┴─────────────┐
-17)│ DataSourceExec │
-18)│ -------------------- │
-19)│ files: 1 │
-20)│ format: csv │
-21)└───────────────────────────┘
+03)│ -------------------- │
+04)│ aggr: │
+05)│ sum(table1.bigint_col) │
+06)│ │
+07)│ group_by: @0 │
Review Comment:
why is this showing `@0`?
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -809,8 +809,54 @@ impl DisplayAs for AggregateExec {
}
}
DisplayFormatType::TreeRender => {
- // TODO: collect info
- write!(f, "")?;
+ let g: Vec<String> = if self.group_by.is_single() {
Review Comment:
there seems to be quite a bit of formatting code here -- but many of the cases are not covered by the tests
can you explain what it is trying to do?
Perhaps you are trying to make the expressions better to read, similar to
- https://github.com/apache/datafusion/issues/15107
What I suggest for this PR is:
1. Follow the existing patterns for `tree` mode
2. Ensure any important case is covered by tests
And then we can work on making expression printing nicer as a follow on PR (and so it applies to all `tree` modes)
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#issuecomment-2715508162
I also tested that these tests pass on main after merging up
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "zebsme (via GitHub)" <gi...@apache.org>.
zebsme commented on code in PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#discussion_r1988851050
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -809,8 +809,60 @@ impl DisplayAs for AggregateExec {
}
}
DisplayFormatType::TreeRender => {
- // TODO: collect info
- write!(f, "")?;
+ let g: Vec<String> = if self.group_by.is_single() {
+ self.group_by
+ .expr
+ .iter()
+ .map(|(e, alias)| {
+ let e = e.to_string();
+ if &e != alias {
+ format!("{e} as {alias}")
+ } else {
+ e
+ }
Review Comment:
Thank you @Weijun-H -- amazing suggestion :)
and already updated
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#discussion_r1988354902
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -809,8 +809,60 @@ impl DisplayAs for AggregateExec {
}
}
DisplayFormatType::TreeRender => {
- // TODO: collect info
- write!(f, "")?;
+ let g: Vec<String> = if self.group_by.is_single() {
+ self.group_by
+ .expr
+ .iter()
+ .map(|(e, alias)| {
+ let e = e.to_string();
+ if &e != alias {
+ format!("{e} as {alias}")
+ } else {
+ e
+ }
Review Comment:
Could you extract this logic? It would greatly increase readability.
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #15103:
URL: https://github.com/apache/datafusion/pull/15103
--
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] Implement tree explain for AggregateExec [datafusion]
Posted by "zebsme (via GitHub)" <gi...@apache.org>.
zebsme commented on code in PR #15103:
URL: https://github.com/apache/datafusion/pull/15103#discussion_r1986332402
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -809,8 +809,54 @@ impl DisplayAs for AggregateExec {
}
}
DisplayFormatType::TreeRender => {
- // TODO: collect info
- write!(f, "")?;
+ let g: Vec<String> = if self.group_by.is_single() {
Review Comment:
hi @alamb, sorry for the mistake. Let me clarify my original thoughts. I noticed that DuckDB provides full expressions for aggregations while only index for group_by:
```
┌─────────────┴─────────────┐
│ HASH_GROUP_BY │
│ ──────────────────── │
│ Groups: │
│ #0 │
│ #1 │
│ │
│ Aggregates: │
│ sum_no_overflow(#2) │
│ min(#3) │
│ │
│ ~0 Rows │
└─────────────┬─────────────┘
```
But as you pointed out, it lacks test coverage — my apologies, maybe i can finish it in the future :)
--
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