fix(unparser): make BigQueryDialect more robust#21296
Merged
alamb merged 3 commits intoApr 19, 2026
Merged
Conversation
nuno-faria
approved these changes
Apr 12, 2026
Contributor
nuno-faria
left a comment
There was a problem hiding this comment.
Thanks @sgrebnov, I doubled checked with sqlglot and LGTM.
nuno-faria
approved these changes
Apr 17, 2026
Rich-T-kid
pushed a commit
to Rich-T-kid/datafusion
that referenced
this pull request
Apr 21, 2026
## Which issue does this PR close? PR improves `BigQueryDialect` dialect to make generated SQL `BigQuery`-compatible (fix execution errors). ## What changes are included in this PR? Eight `Dialect` trait overrides added to `BigQueryDialect`: https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types 1. `date_field_extract_style` → `Extract` + `scalar_function_to_sql_overrides` BigQuery does not support `date_part()`. TPC-H Q7, Q8, Q9 fail with `Function not found: date_part`. | Before (error) | After | |---|---| | `date_part('YEAR', l_shipdate)` | `EXTRACT(YEAR FROM l_shipdate)` | 2. `interval_style` → `SQLStandard` BigQuery does not support PostgreSQL-style interval abbreviations. TPC-H Q4, Q20 fail with `Syntax error: Unexpected ")"`. | Before (error) | After | |---|---| | `INTERVAL '3 MONS'` | `INTERVAL '3' MONTH` | 3. `float64_ast_dtype` → `Float64` BigQuery does not support `DOUBLE`. Fails with `Type not found: DOUBLE`. | Before (error) | After | |---|---| | `CAST(a AS DOUBLE)` | `CAST(a AS FLOAT64)` | 4. `supports_column_alias_in_table_alias` → `false` BigQuery does not support column aliases in table alias definitions. Fails with `Expected ")" but got "("`. | Before (error) | After | |---|---| | `SELECT c.key FROM (...) AS c(key)` | `SELECT c.key FROM (SELECT o_orderkey AS key FROM orders) AS c` | 5. `utf8_cast_dtype` + `large_utf8_cast_dtype` → `String` BigQuery does not support `VARCHAR`/`TEXT`. Fails with `Type not found: VARCHAR`, `Type not found: Text`. | Before (error) | After | |---|---| | `CAST(a AS VARCHAR)` | `CAST(a AS STRING)` | | `CAST(a AS TEXT)` | `CAST(a AS STRING)` | 6. ~`int64_cast_dtype` → `Int64`~ 7. `timestamp_cast_dtype` → `Timestamp` (no timezone qualifier) https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types#timestamp_type BigQuery does not support `TIMESTAMP WITH TIME ZONE`. Fails with `Syntax error: Expected ')' or keyword FORMAT but got keyword WITH`. `TIMESTAMP` should be used (preserves time zone information)/ | Before (error) | After | |---|---| | `CAST(a AS TIMESTAMP WITH TIME ZONE)` | `CAST(a AS TIMESTAMP)` | ## Are these changes tested? Yes. Added `test_bigquery_dialect_overrides` unit test covering all eight overrides, verified against BigQuery before and after. ## Are there any user-facing changes? No API changes. `BigQueryDialect` now generates valid BigQuery SQL for the affected expressions.
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?
PR improves
BigQueryDialectdialect to make generated SQLBigQuery-compatible (fix execution errors).What changes are included in this PR?
Eight
Dialecttrait overrides added toBigQueryDialect:https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types
date_field_extract_style→Extract+scalar_function_to_sql_overridesBigQuery does not support
date_part(). TPC-H Q7, Q8, Q9 fail withFunction not found: date_part.date_part('YEAR', l_shipdate)EXTRACT(YEAR FROM l_shipdate)interval_style→SQLStandardBigQuery does not support PostgreSQL-style interval abbreviations. TPC-H Q4, Q20 fail with
Syntax error: Unexpected ")".INTERVAL '3 MONS'INTERVAL '3' MONTHfloat64_ast_dtype→Float64BigQuery does not support
DOUBLE. Fails withType not found: DOUBLE.CAST(a AS DOUBLE)CAST(a AS FLOAT64)supports_column_alias_in_table_alias→falseBigQuery does not support column aliases in table alias definitions. Fails with
Expected ")" but got "(".SELECT c.key FROM (...) AS c(key)SELECT c.key FROM (SELECT o_orderkey AS key FROM orders) AS cutf8_cast_dtype+large_utf8_cast_dtype→StringBigQuery does not support
VARCHAR/TEXT. Fails withType not found: VARCHAR,Type not found: Text.CAST(a AS VARCHAR)CAST(a AS STRING)CAST(a AS TEXT)CAST(a AS STRING)int64_cast_dtype→Int64timestamp_cast_dtype→Timestamp(no timezone qualifier)https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types#timestamp_type
BigQuery does not support
TIMESTAMP WITH TIME ZONE. Fails withSyntax error: Expected ')' or keyword FORMAT but got keyword WITH.TIMESTAMPshould be used (preserves time zone information)/CAST(a AS TIMESTAMP WITH TIME ZONE)CAST(a AS TIMESTAMP)Are these changes tested?
Yes. Added
test_bigquery_dialect_overridesunit test covering all eight overrides, verified against BigQuery before and after.Are there any user-facing changes?
No API changes.
BigQueryDialectnow generates valid BigQuery SQL for the affected expressions.