fix(substrait): plan nested projected window expressions#22630
Open
bvolpato wants to merge 1 commit into
Open
Conversation
Collect window expressions recursively when consuming ProjectRel so scalar-wrapped windows are placed in WindowAggr nodes before physical planning. Add an executing Substrait fixture regression for 1 + count(*) OVER (). Refs apache#22629.
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.
Which issue does this PR close?
Rationale for this change
The Substrait
ProjectRelconsumer only added aWindowAggrrelation when the root projected expression was aWindowFunction. A scalar expression wrapping a valid window function therefore left the window directly insideProjection, which cannot be physically planned.Minimal reproducer represented by the added Substrait fixture:
Before this patch, the regression test produced this plan difference:
This is the same class of failure that reaches physical planning as an unsupported nested
WindowFunctionexpression.What changes are included in this PR?
find_window_exprs(...)recursion while consuming SubstraitProjectRelexpressions, retaining currentHashSetdeduplication across projections.WindowAggris inserted and physically executable.Are these changes tested?
Pre-fix evidence:
cargo test -p datafusion-substrait --test substrait_integration nested_window_function_in_expression -- --nocapturefailed because the consumed plan omitted expectedWindowAggrand putProjectiondirectly aboveTableScan.Final validation on Apache
maincommitd8c458828:cargo fmt --all -- --checkcargo test -p datafusion-substrait(49 unit passed, 200 integration passed, 3 doctests passed; 6 existing ignored)cargo check --all-targets -p datafusion-substraitcargo check --no-default-features -p datafusion-substraitcargo check --no-default-features -p datafusion-substrait --features=physicalcargo check --no-default-features -p datafusion-substrait --features=protoccargo clippy --all-targets --all-features -- -D warnings./dev/rust_lint.shAre there any user-facing changes?
Substrait producers may now send projected expressions that contain nested window functions; DataFusion consumes them into executable logical plans instead of leaving unsupported window expressions in projections.