fix(substrait): Correctly parse field references in subqueries#20439
Open
neilconway wants to merge 2 commits intoapache:mainfrom
Open
fix(substrait): Correctly parse field references in subqueries#20439neilconway wants to merge 2 commits intoapache:mainfrom
neilconway wants to merge 2 commits intoapache:mainfrom
Conversation
e100c43 to
d0437e0
Compare
Contributor
Author
|
Hi @gabotechs @waynexia Would you have time to take a quick look at this when you get a chance? Thank you! |
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 consumer parsed field references in correlated subqueries incorrectly. Field references were always resolved relative to the schema of the current (innermost) subquery, leading to incorrect results.
What changes are included in this PR?
We now maintain a stack of outer query schemas, and pushes/pops elements from it as we traverse subqueries. When resolving field references, we now use
FieldReference.root_typeto detect outer query field references and resolve them against the appropriate schema.This commit updates the expected results for parsing TPC-H queries, because several of them were parsed incorrectly (the misparsing was probably not detected because the incorrect parse didn't result in any illegal queries, by sheer luck). This also means we can enable Q17, which failed to parse before.
Are these changes tested?
Yes. Test results updated to reflect new, correct behavior, and new unit tests added.
Are there any user-facing changes?
The behavior of the substrait consumer has changed, although the previous behavior was wrong and it seems a bit unlikely anyone would have dependend on it. The
DefaultSubstraitConsumerAPI is slightly changed (new private field).