Skip to content
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

fix(optimizer)!: Mark UDTF child scopes as ScopeType.SUBQUERY #3390

Merged
merged 1 commit into from
May 1, 2024

Conversation

VaggelisD
Copy link
Collaborator

BigQuery supports correlated join operations which allow join RHS UDTFs to reference columns from the LHS. Example:

WITH cte AS (
  SELECT 1 AS col
) 
SELECT * FROM cte 
LEFT JOIN UNNEST((
   SELECT ARRAY_AGG(DISTINCT x) AS agg FROM UNNEST([1]) AS x WHERE col = 1
));

However, UDTFs currently mark their nested scopes as ScopeType.DERIVED_TABLE which not only seems semantically incorrect but also blocks the parent/outer scope from collecting & qualifying the UNNEST external columns, as would happen in a typical correlated subquery.

@VaggelisD VaggelisD changed the title fix(optimizer): Mark UDTF child scopes as ScopeType.SUBQUERY fix(optimizer)!: Mark UDTF child scopes as ScopeType.SUBQUERY May 1, 2024
@VaggelisD VaggelisD merged commit cc6259d into main May 1, 2024
5 checks passed
@VaggelisD VaggelisD deleted the vaggelisd/udtf_qualify branch May 1, 2024 15:12
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.

None yet

4 participants