Skip to content

feat(googlesql/parser-ddl-spanner): CHANGE STREAM / SEQUENCE / ROLE / LOCALITY GROUP / PROTO BUNDLE + role GRANT#246

Merged
h3n4l merged 1 commit into
mainfrom
googlesql/parser-ddl-spanner
Jun 5, 2026
Merged

feat(googlesql/parser-ddl-spanner): CHANGE STREAM / SEQUENCE / ROLE / LOCALITY GROUP / PROTO BUNDLE + role GRANT#246
h3n4l merged 1 commit into
mainfrom
googlesql/parser-ddl-spanner

Conversation

@h3n4l

@h3n4l h3n4l commented Jun 5, 2026

Copy link
Copy Markdown
Member

Node: googlesql/parser-ddl-spanner

Spanner-specific object DDL that the legacy ANTLR GoogleSQLParser.g4 has no first-class rule for — it models CHANGE STREAM / ROLE / LOCALITY GROUP on the generic-entity hook (which can't express the two-word object type + clauses) and grant_statement/revoke_statement accept only string-literal grantees. The omni parser, whose authoritative oracle for Spanner DDL is the live Cloud Spanner emulator (oracle.md), parses each as a dedicated statement so bytebase's Spanner consumers (Diagnose / GetQuerySpan / SplitSQL) see a real tree instead of a false syntax error.

Forms implemented (all emulator-accept-verified)

Object Forms truth1
CHANGE STREAM CREATE (FOR ALL / FOR table_and_column [,…] / OPTIONS), ALTER (SET FOR/DROP FOR ALL/SET OPTIONS), DROP DDL-024/025/026
SEQUENCE CREATE [IF NOT EXISTS] [OPTIONS], ALTER [IF EXISTS] SET OPTIONS, DROP [IF EXISTS] DDL-027/028/029
ROLE CREATE ROLE, DROP ROLE DDL-032/033
role GRANT/REVOKE … TO/FROM ROLE r [,…], GRANT/REVOKE ROLE r [,…] TO/FROM ROLE r [,…], comma-separated object lists ON TABLE t1, t2 TO ROLE r DDL-034-037
LOCALITY GROUP CREATE [OPTIONS], ALTER [SET OPTIONS] (optional), DROP DDL-041/042/043
PROTO BUNDLE CREATE ( type [,…] ), ALTER INSERT?/UPDATE?/DELETE? (fixed order) DDL-046/047

Design

  • New AST nodes in ast/parsenodes.go (+ tags in nodetags.go, regenerated walk_generated.go). The role surface reuses the shared GrantStmt/RevokeStmt via a new GranteeRole grantee kind + Roles/Paths fields, so one union parser serves both the legacy ZetaSQL string-grantee dialect AND the Spanner role dialect.
  • New parsers: spanner_change_stream.go, spanner_sequence.go (sequence + locality group + proto bundle), spanner_schema_role.go (role + role-grant helpers).
  • Dispatch wired in create_table.go / alter_table.go / drop.go (CHANGE/LOCALITY are bare identifiers matched by spelling; SEQUENCE/PROTO are keywords) and grant_revoke.go (role-grant disambiguation + comma-object head). analysis/classify.go now classifies the new nodes as DDL.

Proof — differential vs the live emulator (PROVE gate)

spanner_ddl_oracle_test.go runs 81 fixtures, both polarities (accept AND reject) through the emulator via the harness/googlesql-spanner oracle and asserts omni's verdict matches. Run:

SPANNER_EMULATOR_HOST=localhost:9010 go test -tags googlesql_oracle ./googlesql/parser/ -run TestSpannerDDLDifferential

go test ./googlesql/{parser,ast,analysis}/ green; go vet clean. Dialect-divergent forms (legacy ZetaSQL string-grantee GRANT, empty OPTIONS (), object-named-keyword, no-type-keyword role grant) are EXCLUDED from the Spanner differential (emulator non-authoritative for the BigQuery/union dialect) and covered by unit tests instead.

Owned divergences

  • feat(pg): add completion scope context #112 closedINTERLEAVE IN PARENT … ON DELETE made optional in create_table.go (defaults to NO ACTION per DDL-007); the original port over-rejected the documented default and the emulator-accepted INTERLEAVE IN PARENT p. A dangling ON DELETE still rejects.
  • fix(cosmosdb): fix position tracking and reject semicolons #8 closed — inline column PRIMARY KEY already accepted by the union parser (matches emulator); guarded by a regression test.
  • feat(oracle): add lexer-based splitter #128 flagged — column-level GRANT (GRANT SELECT(cols) … TO ROLE): valid GoogleSQL (DDL-034) but the emulator rejects with "does not yet support column level access controls" (an emulator limitation, non-authoritative); the union parser accepts per docs.
  • flagged — the central "Spanner object DDL is first-class, not generic-entity / role grantees not in legacy" dialect divergence (oracle + grammar-source evidence in the ledger).

Review

Two-reviewer gate. The Codex lens caught 3 real bugs (all fixed + regression-tested): (1) legacy GRANT ROLE ON … misrouted to the role-grant path, (2) over-permissive non-ROLE target on a role grant, (3) over-rejected comma-separated object lists. Oracle-driven follow-ups while fixing: role names are single identifiers (CREATE ROLE rejects dotted; DROP ROLE accepts a path), a comma-object list requires both a type keyword and ROLE grantees, and PROTO BUNDLE lists allow a trailing comma (change-stream column lists do not). The Claude lens ran as an adversarial self-review across all angles.

Scope note

The node's declared writes-globs centered on the new spanner_*.go files + the AST. The CREATE/ALTER/DROP/GRANT dispatch actually lives in create_table.go/alter_table.go/drop.go/grant_revoke.go (not parser.go), and the query-type classifier in analysis/classify.go — those out-of-scope edits were the minimal wiring + cross-node correctness needed to make the new forms parse and classify; recorded in the worker summary.

🤖 Generated with Claude Code

… LOCALITY GROUP / PROTO BUNDLE + role GRANT

Implements the Spanner-specific object DDL the legacy ANTLR grammar has no
first-class rule for (it rides them on the generic-entity hook or rejects them):

  - CREATE/ALTER/DROP CHANGE STREAM  (truth1 DDL-024/025/026)
  - CREATE/ALTER/DROP SEQUENCE        (DDL-027/028/029)
  - CREATE/DROP ROLE                  (DDL-032/033)
  - role-based GRANT/REVOKE: `… TO/FROM ROLE r [, ...]` and
    `GRANT/REVOKE ROLE r [, ...] TO/FROM ROLE r [, ...]`, plus the Spanner
    comma-separated object list `ON TABLE t1, t2 TO ROLE r`  (DDL-034-037)
  - CREATE/ALTER/DROP LOCALITY GROUP  (DDL-041/042/043)
  - CREATE/ALTER PROTO BUNDLE          (DDL-046/047)

New AST nodes (parsenodes.go + nodetags.go + regenerated walk_generated.go) plus
a GranteeRole grantee kind and Roles/Paths fields on the shared GrantStmt/
RevokeStmt so one union parser serves both the legacy ZetaSQL string-grantee
dialect and the Spanner role dialect. Dispatch wired in create_table.go /
alter_table.go / drop.go (the CHANGE/LOCALITY bare-identifier words and the
SEQUENCE/PROTO keywords) and in grant_revoke.go (role-grant disambiguation +
comma-object head). analysis/classify.go classifies the new nodes as DDL.

Authoritative oracle: the live Cloud Spanner emulator (docs/migration/googlesql/
oracle.md). PROVE gate = spanner_ddl_oracle_test.go differential, both polarities
(81 fixtures, omni == emulator). Spanner is authoritative for these forms.

Owned divergences closed:
  - #112 INTERLEAVE IN PARENT ON DELETE made OPTIONAL (defaults to NO ACTION) in
    create_table.go — the original port over-rejected the documented default.
  - #8  inline column PRIMARY KEY already accepted (matches emulator) — guarded.
Flagged (oracle non-authoritative / docs-backed): #128 column-level GRANT, and the
central "Spanner object DDL is first-class, not generic-entity" dialect divergence.

Cross-model (Codex) review caught 3 real bugs (now fixed + regression-tested):
role-grant misroute of legacy `GRANT ROLE ON …`, over-permissive non-ROLE
role-grant target, and over-rejected comma-separated object lists. Oracle-driven
follow-ups: role names are single identifiers (CREATE ROLE rejects dotted; DROP
ROLE accepts), comma-object lists require a type keyword + ROLE grantees, and
PROTO BUNDLE lists allow a trailing comma (change-stream column lists do not).

go test ./googlesql/{parser,ast,analysis}/ green; differential green; vet clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@h3n4l h3n4l merged commit 982666b into main Jun 5, 2026
2 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.

1 participant