Skip to content

feat: add GoogleSQL support to sqlc parse#4504

Merged
kyleconroy merged 1 commit into
mainfrom
claude/googlesql-parse-824d4e72
Jul 5, 2026
Merged

feat: add GoogleSQL support to sqlc parse#4504
kyleconroy merged 1 commit into
mainfrom
claude/googlesql-parse-824d4e72

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

Adds a googlesql dialect to sqlc parse, backed by github.com/sqlc-dev/zetajones — a pure-Go (no cgo) GoogleSQL/ZetaSQL parser that passes the entire upstream google/googlesql parser golden-test corpus (~4,700 cases, byte-for-byte including error messages and caret positions).

sqlc parse --dialect googlesql queries.sql
echo "SELECT id FROM users WHERE status = @status" | sqlc parse --dialect googlesql

Structure

Follows the ClickHouse integration (#4267) exactly. New files in internal/engine/googlesql/:

  • parse.go — Parser implementation using zetajones
  • convert.go — AST converter from zetajones to sqlc AST
  • utils.go — helpers (identifiers, string-literal unquoting, type rendering)
  • catalog.go, stdlib.go — catalog initialization
  • reserved.go — reserved keywords (delegates to zetajones/token)

Coverage

  • Queries: SELECT list (aliases, *, expr.*), FROM (dotted table paths, JOINs, table subqueries incl. LATERAL, TVFs, UNNEST), WHERE, GROUP BY, HAVING, DISTINCT, ORDER BY, LIMIT/OFFSET, WITH/CTEs (incl. RECURSIVE), set operations
  • DML: INSERT (VALUES + SELECT forms), UPDATE, DELETE — all incl. THEN RETURNReturningList
  • DDL: CREATE TABLE (types, NOT NULL, PRIMARY KEY, type params, DEFAULT), DROP TABLE, TRUNCATE
  • Expressions: literals, paths, boolean logic, BETWEEN/IN/IS NULL, CASE, CAST, subqueries (EXISTS/ARRAY/scalar), function calls incl. COUNT(*) and window functions, array subscripts

Design notes:

  • Named parameters (@name) convert to the same A_Expr{"@"} shape the PostgreSQL and SQLite engines produce, so rewrite.NamedParameters consumes them unchanged. Positional ? → numbered ParamRef.
  • Identifiers pass through case-sensitively (BigQuery table names are case-sensitive); function/type names, which GoogleSQL treats case-insensitively, are lowercased.
  • Unsupported constructs (graph queries, scripts, pipe operators, MATCH_RECOGNIZE) convert to ast.TODO without panicking — the underlying parser is fuzz-tested (12M+ executions, no panics).

Testing

  • go build ./..., go vet, gofmt clean; go test ./internal/engine/... ./internal/cmd/... ./internal/sql/... all pass
  • Smoke battery over SELECT/JOIN/CREATE/INSERT/UPDATE/DELETE produces fully-populated ASTs (no TODOs), and unsupported statements exit cleanly

🤖 Generated with Claude Code

@kyleconroy kyleconroy force-pushed the claude/googlesql-parse-824d4e72 branch from 6c8692d to fe764e3 Compare July 5, 2026 13:55
Add a googlesql dialect backed by github.com/sqlc-dev/zetajones, a pure-Go
GoogleSQL/ZetaSQL parser that passes the entire upstream googlesql parser
golden-test corpus.

New files in internal/engine/googlesql/:
- parse.go: Parser implementation using zetajones
- convert.go: AST converter from zetajones to sqlc AST
- utils.go: helpers (identifiers, string unquoting, type rendering)
- catalog.go, stdlib.go: catalog initialization
- reserved.go: reserved keywords (delegates to zetajones/token)

Covers SELECT (joins, subqueries, CTEs, set ops, window functions),
INSERT/UPDATE/DELETE (incl. THEN RETURN), CREATE/DROP/TRUNCATE TABLE, and
expressions incl. named @params (mapped to the same A_Expr shape the
PostgreSQL engine produces, so the named-parameter rewriter consumes them).
Unsupported constructs convert to ast.TODO without panicking.

Includes an end-to-end case at testdata/parse_basic/googlesql following
the config-less exec.json harness.

Usage: sqlc parse --dialect googlesql queries.sql

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kyleconroy kyleconroy force-pushed the claude/googlesql-parse-824d4e72 branch from fe764e3 to 5f7e289 Compare July 5, 2026 14:35
@kyleconroy kyleconroy merged commit 22d878a into main Jul 5, 2026
13 checks passed
@kyleconroy kyleconroy deleted the claude/googlesql-parse-824d4e72 branch July 5, 2026 15:06
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