fix missing window expressions when unparsing plans without outer projections#21801
Merged
kosiew merged 5 commits intoMay 15, 2026
Merged
Conversation
| .alias("row_idx"); | ||
| let plan = table_scan(Some("gas"), &schema, None)? | ||
| .aggregate(vec![col("time")], vec![sum(col("value")).alias("sum_n")])? | ||
| .window(vec![window_expr])? |
There was a problem hiding this comment.
I tried to access the row_idx column here in a filter just by inserting this expression:
.filter(col("row_idx").eq(lit(0i64)))?
and the unparser fails with this error: Error: Internal("Tried to unproject agg expr for column 'row_idx' that was not found in the provided Aggregate!")
when accessing the "sum_n" column there is no problem.
Contributor
Author
There was a problem hiding this comment.
yea makes sense just fixed:
- For Filter nodes, the unparser now checks for windows first when the dialect supports QUALIFY.
- If there is also an aggregate underneath, aggregate aliases inside the QUALIFY expression are still unprojected correctly.
There was a problem hiding this comment.
Yes, I tested on my side and it fixes the issue. Thank you so much!
PiotrSrebrny
left a comment
There was a problem hiding this comment.
It works pretty well, but there is still some issue. Please have a look at my comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addressing: #21746
Fixes a problem with
plan_to_sqlwhere window expressions could be dropped when unparsing plans that have aWindownode without an outerProjectionPR solution
When unparsing a
LogicalPlan::Window, if no projection has already reconstructed the output, the unparser now appends the window expressions itself.This preserves window outputs for plans like:
Additionally:
DISTINCT,LIMIT,SORT,UNION, and childProjectionboundaries are preserved by deriving the window input before appending window output.Subquery/SubqueryAliasboundaries, so outer windows reference derived columns instead of incorrectly looking through the subquery.