Skip to content

Add analyze support for GoogleSQL via zetajones#4522

Open
kyleconroy wants to merge 1 commit into
mainfrom
claude/googlesql-parse-analyze-jspjk8
Open

Add analyze support for GoogleSQL via zetajones#4522
kyleconroy wants to merge 1 commit into
mainfrom
claude/googlesql-parse-analyze-jspjk8

Conversation

@kyleconroy

@kyleconroy kyleconroy commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Overview

Wires the GoogleSQL (zetajones) engine into sqlc's native static analysis so sqlc analyze --dialect googlesql infers result columns and parameters from a schema, mirroring the existing PostgreSQL, MySQL, and SQLite support. GoogleSQL parse support already landed in #4504; this builds analyze on top of it and fixes several bugs that surfaced once real queries flowed through the compiler.

Changes

Engine wiring

  • Add the googlesql engine constant and register its parser, catalog, and selector in the compiler.
  • Accept googlesql as an analyze dialect; update the command's help text and flag description.

Parameters & identifiers

  • Keep named parameters in their native @name form when rewriting, since GoogleSQL supports named parameters (Spanner requires them). Previously they were rewritten to $1, which is invalid GoogleSQL and failed the re-parse validation step.
  • Quote identifiers with backticks during SELECT * / RETURNING * star expansion.

Parser location fix

  • Include a statement's leading comment in its reported location so the -- name: annotation is captured. Previously StmtLocation pointed past the comment, so analyze found no named queries. This also fixes name extraction for sqlc parse --dialect googlesql.

Nil-pointer panics

  • Initialize the list fields the compiler walks unconditionally — ReturningList on INSERT/UPDATE/DELETE, TargetList on INSERT ... VALUES, and FromClause on UPDATE — matching the convention the other engines follow. Without these, analyzing DML statements panicked.

Docs

  • Document googlesql as an analyze dialect, and add the previously-undocumented googlesql dialect to the parse reference.

Tests

All new tests are end-to-end fixtures under internal/endtoend/testdata/, run by TestReplay. No unit tests were added.

  • analyze_basic/googlesql — basic SELECT with a named parameter.
  • analyze_dml/googlesql — INSERT, INSERT ... THEN RETURN, UPDATE, and DELETE (regression coverage for the panics above).
  • Regenerated the parse_basic/googlesql golden file, which now includes the extracted query name/command.

The parse/analyze end-to-end tests pass, and gofmt and go vet are clean. (The pre-existing compiler/config unit suites were also run as a sanity check and remain green, but this PR adds no unit tests.)

Known limitation

Aggregate functions such as COUNT(*) currently report data_type: "any" because the GoogleSQL catalog has no function signatures yet — a reasonable follow-up for richer type inference.

🤖 Generated with Claude Code

Wire the GoogleSQL (zetajones) engine into sqlc's native static analysis so
`sqlc analyze --dialect googlesql` infers result columns and parameters from a
schema, mirroring the existing PostgreSQL, MySQL, and SQLite support.

Changes:
- Add the `googlesql` engine constant and register its parser, catalog, and
  selector in the compiler.
- Accept `googlesql` as an `analyze` dialect and document it (and the
  previously-undocumented `parse` dialect).
- Keep named parameters in their native `@name` form when rewriting, since
  GoogleSQL supports named parameters (Spanner requires them), and quote
  identifiers with backticks during star expansion.
- Include a statement's leading comment in its reported location so the
  `-- name:` annotation is captured; this also fixes name extraction for
  `sqlc parse --dialect googlesql`.
- Initialize the list fields the compiler walks unconditionally
  (ReturningList, INSERT ... VALUES TargetList, UPDATE FromClause), fixing
  nil-pointer panics when analyzing INSERT/UPDATE/DELETE statements.

Add end-to-end coverage for basic SELECT analysis and for INSERT/UPDATE/DELETE
(including THEN RETURN).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmGTScco7g1CNc5LjPSJVd
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