feat(pg): add completion scope context#112
Merged
Merged
Conversation
h3n4l
added a commit
that referenced
this pull request
Jun 5, 2026
) Add the googlesql/analysis package — the omni counterpart of bytebase's legacy plugin/parser/{bigquery,spanner} GetQuerySpan + queryTypeListener + accessTableListener. It is parser-driven and best-effort (the established trino/doris/snowflake analysis-peer pattern): self-contained local types that the bytebase-switch node maps onto base.QuerySpan; no live-metadata resolution. - classify.go: dialect-aware QueryType classification (Select / DML / DDL / SelectInfoSchema / Unknown) over the merged googlesql AST. SelectInfoSchema promotion follows the legacy allSystems rule (a query reading EXCLUSIVELY system tables), evaluated over the AST's access tables. - query_span.go: GetQuerySpan walks the fully-connected AST (subqueries are parsed into real QueryStmt nodes, so no re-parse) to produce AccessTables, Results, PredicateColumns, and CTEs. Per-dialect divergences (contract.md §4) parameterized by a Dialect enum: - metadata model: BigQuery project.dataset.table (2nd-to-last is Database unless INFORMATION_SCHEMA) vs Spanner db.schema.table (2nd-to-last always Schema). One shared bucketNameParts rule for tables AND column refs. - system schemas: BigQuery INFORMATION_SCHEMA only; Spanner adds SPANNER_SYS. PROVE: oracle_test.go runs the analysis slice of the differential against the live Cloud Spanner emulator (tag googlesql_oracle) — confirms every classify- corpus statement is real GoogleSQL the grammar accepts and cross-checks the read-only classification. go test ./googlesql/analysis green (113 cases); race-clean. REVIEW: two-reviewer gate (Claude lens + Codex lens), 4 rounds, all findings fixed with a permanent regression test each (regression_test.go): dialect-aware column bucketing; Spanner 3-part Database; DDL object-kind gating + LIKE/CLONE/ INTERLEAVE/FK source refs; TRUNCATE WHERE; TVF predicate columns; WITH-expr progressive var scoping; project-qualified INFORMATION_SCHEMA catalog; sequential non-recursive CTE visibility; correlated array/field FROM paths (incl. derived and chained). Flagged divergence #112 (parser-ddl-spanner, NOT this node): the merged parser over-rejects bare INTERLEAVE IN PARENT without ON DELETE, which the Spanner emulator accepts. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
h3n4l
added a commit
that referenced
this pull request
Jun 5, 2026
… LOCALITY GROUP / PROTO BUNDLE + role GRANT (#246) 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>
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.
Summary
Test Plan