Skip to content

fix(unparser): make BigQueryDialect more robust#21296

Open
sgrebnov wants to merge 1 commit intoapache:mainfrom
spiceai:sgrebnov/0410-bigquery-unparsing-improve
Open

fix(unparser): make BigQueryDialect more robust#21296
sgrebnov wants to merge 1 commit intoapache:mainfrom
spiceai:sgrebnov/0410-bigquery-unparsing-improve

Conversation

@sgrebnov
Copy link
Copy Markdown
Member

@sgrebnov sgrebnov commented Apr 1, 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_styleExtract + 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)
  1. interval_styleSQLStandard

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
  1. float64_ast_dtypeFloat64

BigQuery does not support DOUBLE. Fails with Type not found: DOUBLE.

Before (error) After
CAST(a AS DOUBLE) CAST(a AS FLOAT64)
  1. supports_column_alias_in_table_aliasfalse

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
  1. utf8_cast_dtype + large_utf8_cast_dtypeString

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)
  1. int64_cast_dtypeInt64

BigQuery does not support BIGINT. Fails with Type not found: BIGINT.

A 64-bit integer.
SQL type name: INT64
SQL aliases: INT, SMALLINT, INTEGER, BIGINT, TINYINT, BYTEINT

Before (error) After
CAST(a AS BIGINT) CAST(a AS INT64)
  1. timestamp_cast_dtypeTimestamp (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.

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