Add analyze support for GoogleSQL via zetajones#4522
Open
kyleconroy wants to merge 1 commit into
Open
Conversation
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
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.
Overview
Wires the GoogleSQL (zetajones) engine into sqlc's native static analysis so
sqlc analyze --dialect googlesqlinfers result columns and parameters from a schema, mirroring the existing PostgreSQL, MySQL, and SQLite support. GoogleSQLparsesupport already landed in #4504; this buildsanalyzeon top of it and fixes several bugs that surfaced once real queries flowed through the compiler.Changes
Engine wiring
googlesqlengine constant and register its parser, catalog, and selector in the compiler.googlesqlas ananalyzedialect; update the command's help text and flag description.Parameters & identifiers
@nameform 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.SELECT */RETURNING *star expansion.Parser location fix
-- name:annotation is captured. PreviouslyStmtLocationpointed past the comment, soanalyzefound no named queries. This also fixes name extraction forsqlc parse --dialect googlesql.Nil-pointer panics
ReturningListon INSERT/UPDATE/DELETE,TargetListonINSERT ... VALUES, andFromClauseon UPDATE — matching the convention the other engines follow. Without these, analyzing DML statements panicked.Docs
googlesqlas ananalyzedialect, and add the previously-undocumentedgooglesqldialect to theparsereference.Tests
All new tests are end-to-end fixtures under
internal/endtoend/testdata/, run byTestReplay. 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).parse_basic/googlesqlgolden file, which now includes the extracted query name/command.The parse/analyze end-to-end tests pass, and
gofmtandgo vetare 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 reportdata_type: "any"because the GoogleSQL catalog has no function signatures yet — a reasonable follow-up for richer type inference.🤖 Generated with Claude Code