feat(duckdb): transpile BigQuery IN UNNEST(array) to ARRAY_CONTAINS#7892
Merged
Conversation
…TAINS BigQuery uses `value IN UNNEST(array_expr)` to test array membership. DuckDB has no `UNNEST` in this position but provides `ARRAY_CONTAINS`. The transpilation wraps the result in `COALESCE(..., FALSE)` to handle NULL arrays safely — `ARRAY_CONTAINS(NULL, x)` returns NULL in DuckDB, but BigQuery's `IN UNNEST(NULL)` returns FALSE. Adds: - `IN UNNEST(arr)` → `COALESCE(ARRAY_CONTAINS(arr, val), FALSE)` in DuckDB generator via `in_sql` override - Transpilation test for BigQuery → DuckDB
geooo109
reviewed
Jul 17, 2026
Replace COALESCE(ARRAY_CONTAINS(arr, x), FALSE) with a CASE expression that preserves BigQuery's three-valued NULL semantics: - NULL IN UNNEST([1, 2]) → NULL (not FALSE) - 3 IN UNNEST([1, NULL]) → NULL (not FALSE) - 1 IN UNNEST(NULL) → FALSE - 1 IN UNNEST([]) → FALSE Use expression API instead of f-string interpolation per review feedback. Add NOT IN UNNEST test case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
@sirockin is this still a draft? What's pending? |
geooo109
marked this pull request as ready for review
July 21, 2026 11:02
geooo109
reviewed
Jul 21, 2026
Collaborator
|
I will take it to the finish line. |
geooo109
approved these changes
Jul 23, 2026
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.
Summary
BigQuery uses
value IN UNNEST(array_expr)to test array membership. DuckDB has noUNNESTin this position but providesARRAY_CONTAINS.Changes
IN UNNEST(arr)→COALESCE(ARRAY_CONTAINS(arr, val), FALSE)in DuckDB generator viain_sqloverrideCOALESCE(..., FALSE)for null safety —ARRAY_CONTAINS(NULL, x)returns NULL in DuckDB, but BigQuery'sIN UNNEST(NULL)returns FALSEMotivation
We use sqlglot to transpile BigQuery SQL models to DuckDB for local testing via sqlmesh.
IN UNNEST(...)is used in several of our production models for array membership checks but was not previously transpiled to DuckDB.