Skip to content

feat(semantic): transpile SQL to dialect entries - #553

Merged
mmotoyama merged 1 commit into
mainfrom
feat/semantic/transpile-dialect-entries
Oct 24, 2026
Merged

mmotoyama merged 1 commit into
mainfrom
feat/semantic/transpile-dialect-entries

Conversation

@mmotoyama

Copy link
Copy Markdown
Collaborator

Fixes b/573773536.

When --transpile translates a field or metric expression to
BigQuery SQL, transpileModel previously wrote the result only to
the in-memory expression field and skipped ANSI_SQL expressions.
This meant serialized models lost the translated BigQuery SQL, and
ANSI_SQL expressions that wrap column names in double quotes
("orders"."amount", which BigQuery reads as string literals) were
left untranslated.

This PR updates SQL translation in three ways:

  • Store translated SQL as a BIGQUERY entry in dialects (and set
    stringForm to false so bare-string expressions expand into a
    dialects list when serialized) rather than overwriting
    expression. Because translated SQL now lives in dialects,
    validateBigQueryMetrics and measureProblem in validate.ts
    read expressionForDialect(metric, 'BIGQUERY') before falling
    back to metric.expression.
  • Translate ANSI_SQL expressions that double-quote column names
    when no BIGQUERY entry is present, in addition to vendor-only
    expressions. hasDoubleQuotedColumn detects double-quoted column
    names by comparing how the SQL parser reads the expression in
    ANSI_SQL (where both "..." and `...` are quoted column
    identifiers) versus BIGQUERY (where only `...` is).
  • Align POLYGLOT_DIALECTS with PARSER_DIALECTS in
    sql_parser.ts, adding SPANNER (as BigQuery), ALLOYDB (as
    PostgreSQL), and SQLSERVER (as T-SQL), and removing dialect
    names the loader no longer accepts.

@mmotoyama
mmotoyama force-pushed the feat/semantic/transpile-dialect-entries branch 2 times, most recently from a59f39c to 8eac09d Compare October 23, 2026 08:50
@mmotoyama
mmotoyama requested a review from feixufeixu October 23, 2026 09:03

@feixufeixu feixufeixu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three required comments need changes before this merges. The other two are optional.

Comment thread toolbox/mdcode/src/libts/semantic/transpile.ts
Comment thread toolbox/mdcode/tests/tool/commands.test.ts
Comment thread toolbox/mdcode/src/libts/semantic/transpile.ts Outdated
Comment thread toolbox/mdcode/tests/libts/semantic/transpile.polyglot.test.ts
Comment thread toolbox/mdcode/tests/tool/two_phase/catalog_only.test.ts Outdated

@feixufeixu feixufeixu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Please apply the required comments before you merge.

Fixes b/573773536.

When `--transpile` translates a field or metric expression to
BigQuery SQL, `transpileModel` previously wrote the result only to
the in-memory `expression` field and skipped `ANSI_SQL` expressions.
This meant serialized models lost the translated BigQuery SQL, and
`ANSI_SQL` expressions that wrap column names in double quotes
(`"orders"."amount"`, which BigQuery reads as string literals) were
left untranslated.

This PR updates SQL translation in three ways:
- Store translated SQL as a `BIGQUERY` entry in `dialects` (and set
  `stringForm` to `false` so bare-string expressions expand into a
  `dialects` list when serialized) rather than overwriting
  `expression`. Because translated SQL now lives in `dialects`,
  `validateBigQueryMetrics` and `measureProblem` in `validate.ts`
  read `expressionForDialect(metric, 'BIGQUERY')` before falling
  back to `metric.expression`.
- Translate `ANSI_SQL` expressions that double-quote column names
  when no `BIGQUERY` entry is present, in addition to vendor-only
  expressions. `hasDoubleQuotedColumn` detects double-quoted column
  names by comparing how the SQL parser reads the expression in
  `ANSI_SQL` (where both `"..."` and `` `...` `` are quoted column
  identifiers) versus `BIGQUERY` (where only `` `...` `` is).
- Align `POLYGLOT_DIALECTS` with `PARSER_DIALECTS` in
  `sql_parser.ts`, adding `SPANNER` (as BigQuery), `ALLOYDB` (as
  PostgreSQL), and `SQLSERVER` (as T-SQL), and removing dialect
  names the loader no longer accepts.
@mmotoyama
mmotoyama force-pushed the feat/semantic/transpile-dialect-entries branch from 8eac09d to 22de641 Compare October 23, 2026 23:56
@mmotoyama
mmotoyama merged commit 0f75645 into main Oct 24, 2026
7 checks passed
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.

2 participants