fix(bigquery): star referencing outer-scope from correlated subquery - #8291
Open
treysp wants to merge 10 commits into
Open
fix(bigquery): star referencing outer-scope from correlated subquery#8291treysp wants to merge 10 commits into
treysp wants to merge 10 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
georgesittas
reviewed
Sep 1, 2026
georgesittas
left a comment
Collaborator
There was a problem hiding this comment.
@treysp can't we expand the inner/correlated stars as well?
treysp
marked this pull request as draft
September 2, 2026 14:22
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new qualification paths lack regression tests for the documented BigQuery cases.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Balanced
# Conflicts: # sqlglot-integration-tests
A star whose qualifier names a source of an outer scope must be expanded in its own scope, so it is resolved against the resolvers of the scopes it can be correlated with, reusing the ordering guarantees of the post-order scope traversal. This replaces the dialect-gated approach and also makes struct stars honor EXCEPT and REPLACE.
georgesittas
marked this pull request as ready for review
September 7, 2026 13:44
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.
SQLGlot incorrectly raises
OptimizeErrorfor valid BigQuery syntax when a star expression inside a correlated subquery references an outer-scope table alias or STRUCT path.This PR preserves unresolved star expressions in correlatable BigQuery scopes during qualification, leaving validation to Bigquery itself.
Examples
Table reference:
SELECT (SELECT AS STRUCT x.* EXCEPT (a)) AS s FROM x;Struct reference:
SELECT (SELECT AS STRUCT one.* EXCEPT (a_1)) AS s FROM structs;Common dbt pattern:
SELECT * REPLACE((SELECT AS STRUCT payload.* EXCEPT (x)) AS payload) FROM my_table AS t;