Skip to content

fix(bigquery): render GoogleSQL column type changes and escapes - #1341

Merged
kvlonge merged 5 commits into
mainfrom
fix/bigquery-literals
Nov 7, 2026
Merged

kvlonge merged 5 commits into
mainfrom
fix/bigquery-literals

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Why

Two BigQuery renderings produce SQL that BigQuery rejects:

  • Column type changes rendered ALTER COLUMN c TYPE T; GoogleSQL requires SET DATA TYPE T.
  • String literals and quoted identifiers doubled the quote ('it''s', `ab``). GoogleSQL escapes only with a backslash, so values with a quote, backslash or line break failed, including JSON text containing"`.

Changes

  • render_alter_column_types emits SET DATA TYPE.
  • A BigQuery escape table backslash-escapes \, ', CR and LF in _escape_sql_string and _quote_sql_string, so typed scalars, value lists, arrays, typed objects, loader literals and INFORMATION_SCHEMA filters follow it. Typed STRING scalars no longer fall through to the ANSI doubling renderer.
  • render_identifier escapes \, `, CR and LF and keeps ' raw: BigQuery column names may contain an apostrophe, and the janitor matches stored compatibility view definitions against freshly rendered SQL.
  • Tests that pinned the old output expect the GoogleSQL forms; a new BigQuery test covers backslashes, line breaks, JSON escapes, identifiers and SET DATA TYPE.

DuckShop: not applicable. DuckShop runs on DuckDB and never emits BigQuery SQL.

Verification

  • The new and updated cases fail on the previous code (7 failures, for example TYPE NUMERIC and 'it''s') and pass with the fix.
  • An apostrophe identifier renders as before, and view_definitions_match still accepts a stored definition with it.
  • tests/unit/src/sqlbuild/adapters, tests/unit/src/sqlbuild/adapter, tests/integration/src/sqlbuild/adapters and the migrations unit tests pass.
  • GoogleSQL's reference implementation (no warehouse) parses the SET DATA TYPE statement, and every literal and the backtick identifier decode to the original value code point for code point.
  • make check-ci and the public-repository scan.

ALTER COLUMN now uses SET DATA TYPE. String literals and quoted identifiers
escape quotes, backticks, backslashes and line breaks with a backslash, as
GoogleSQL requires, instead of doubling the quote.
BigQuery column names may contain an apostrophe, and stored compatibility view
definitions spell it raw. Escaping it changed the rendered SQL, so the janitor
no longer recognised existing views. Identifiers now escape only backslashes,
backticks and line breaks.
@kvlonge
kvlonge enabled auto-merge (squash) November 7, 2026 08:43
@kvlonge
kvlonge merged commit 18f2ac3 into main Nov 7, 2026
30 checks passed
@kvlonge
kvlonge deleted the fix/bigquery-literals branch November 7, 2026 11:58
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