Uh oh!
There was an error while loading. Please reload this page.
feat: optimize grouping and introduced unparsing and substrait support - #16161
feat: optimize grouping and introduced unparsing and substrait support#16161chenkovsky wants to merge 28 commits into
Conversation
alamb
commented
May 24, 2025
Thanks @chenkovsky -- can. you find the original PR that added this |
@eejbyfeldt@comphead could you please help me review this PR? |
chenkovsky
commented
May 24, 2025
it's related to #12704 |
eejbyfeldt
commented
Jun 17, 2025
I did not look closely at yet since I have not really contributed here in months.
This extra projection is introduced by But the goal of leaving more structure in logical plan after resolving the grouping expr so that optimization and unparsing sounds reasonable to me. |
| bigdecimal = { workspace = true } | ||
| datafusion-common = { workspace = true, default-features = true } | ||
| datafusion-expr = { workspace = true } | ||
| datafusion-functions-aggregate = { workspace = true } |
There was a problem hiding this comment.
We have tried hard to avoid having the sql parser depend on function libraries -- is there any way to avoid changing this dependency?
ed53ae1 to
bf3a290CompareThank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
chenkovsky
commented
Sep 14, 2025
keep it open |
alamb
commented
Sep 16, 2025
Thanks @chenkovsky @eejbyfeldt it looks like you contributed the initial implementation of Could you help review this PR? |
Slimsammylim
commented
Oct 2, 2025
Hi @alamb and @chenkovsky! I am running into the same issue @lorenarosati brought up a couple months ago (#16590) and have not found a workaround solution yet. Just wanted to check in, what's the status of this PR? |
alamb
commented
Oct 2, 2025
I am waiting for someone to help review the PR. Can you help here @Slimsammylim ? Perhaps verify that this solution fixes your issue? |
Slimsammylim
commented
Oct 3, 2025
Hi, I ran my code using this branch and unfortunately it did not solve my issue (#16590). |
chenkovsky
commented
Oct 3, 2025
hi,could you please push your code, then i can see what's your issue. currently i havent touch substrait, some extra codes should be modified to solve issue 16590. |
I added substrait support. @Slimsammylim please try again |
| // To avoid adding datafusion-functions-aggregate dependency, implement a DummyGroupingUDAF here | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| pub struct DummyGroupingUDAF { |
There was a problem hiding this comment.
currently, I created a dummy udaf. maybe we can move grouping udaf to datafusion-expr module directly. because grouping udaf is a pseudo udaf itself.
Slimsammylim
commented
Oct 6, 2025
Hi! I tried again and but I keep getting the same error message. |
Slimsammylim
commented
Oct 6, 2025
@Slimsammylim I see, I only tested roundtrip, you only consume substrait plan. I think the simplest workaround is moving __grouping_id to the end of schema, then index will be correct. but It's too tricky. also there's another issue caused by __grouping_id #16983. It's better to remove __grouping_id. I will work on it |
chenkovsky
commented
Oct 8, 2025
@Slimsammylim I created another PR. #17961 , please take a snapshot. it will not touch grouping udaf in logical plan level. so It will support substrait by design. |
chenkovsky
commented
Oct 19, 2025
In favour of #17961, close this |
Which issue does this PR close?
Rationale for this change
first, it seems that grouping udaf document is not correct.
and for aggregation with grouping,
e.g.
current logical plan is:
the problems are:
there are three projections. for bitwise operation, there's no benifit for extra projection.
it makes grouping level optimization very hard. for example,
we only need to calculate sum(c2) in when grouping(c1) = 1, this is a very useful optimization trick. I'm also using this trick to optimizing sql with multiple count distinct.
unparsing is not supported. Internal("Tried to unproject column referring to internal grouping id") will be thrown.
What changes are included in this PR?
now, the logical plan is:
there are only two projections. and unparsing is supported.
Are these changes tested?
UT
Are there any user-facing changes?
No