Skip to content

Fix(scope)!: include bigquery unnest aliases in selected sources #5285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Jun 25, 2025

This addresses the issue reported in this Slack thread: https://tobiko-data.slack.com/archives/C0448SFS3PF/p1750862162339109. This should only impact users that have queries with UNNEST sources and who build scopes without first calling qualify_tables or qualify on the ASTs.

This example reproduces the error:

from sqlglot import parse_one
from sqlglot.optimizer.scope import build_scope

query = """
SELECT
    ID
    , release
    FROM table
    LEFT JOIN UNNEST(environments) AS env
    LEFT JOIN UNNEST(env.deploySteps) AS release
"""

parsed = parse_one(query, dialect="bigquery")
scope = build_scope(parsed)

print(scope.selected_sources)

@georgesittas georgesittas requested a review from tobymao June 25, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant