feat: add GoogleSQL support to sqlc parse#4504
Merged
Merged
Conversation
6c8692d to
fe764e3
Compare
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>
fe764e3 to
5f7e289
Compare
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.
Adds a
googlesqldialect tosqlc 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).Structure
Follows the ClickHouse integration (#4267) exactly. New files in
internal/engine/googlesql/:parse.go— Parser implementation using zetajonesconvert.go— AST converter from zetajones to sqlc ASTutils.go— helpers (identifiers, string-literal unquoting, type rendering)catalog.go,stdlib.go— catalog initializationreserved.go— reserved keywords (delegates tozetajones/token)Coverage
*,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 operationsTHEN RETURN→ReturningListCOUNT(*)and window functions, array subscriptsDesign notes:
@name) convert to the sameA_Expr{"@"}shape the PostgreSQL and SQLite engines produce, sorewrite.NamedParametersconsumes them unchanged. Positional?→ numberedParamRef.ast.TODOwithout 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🤖 Generated with Claude Code