Skip to content

Commit 6c8692d

Browse files
kyleconroyclaude
andcommitted
feat: add GoogleSQL support to sqlc parse
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. Usage: sqlc parse --dialect googlesql queries.sql Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a95e91d commit 6c8692d

9 files changed

Lines changed: 1323 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
4545
github.com/pingcap/log v1.1.0 // indirect
4646
github.com/rogpeppe/go-internal v1.10.0 // indirect
47+
github.com/sqlc-dev/zetajones v0.1.0 // indirect
4748
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
4849
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
4950
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
8383
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
8484
github.com/sqlc-dev/doubleclick v1.0.0 h1:2/OApfQ2eLgcfa/Fqs8WSMA6atH0G8j9hHbQIgMfAXI=
8585
github.com/sqlc-dev/doubleclick v1.0.0/go.mod h1:ODHRroSrk/rr5neRHlWMSRijqOak8YmNaO3VAZCNl5Y=
86+
github.com/sqlc-dev/zetajones v0.1.0 h1:VeG0atx6lNABr9V2bSI5vL9DvOKTHX0XjMqWUE/rv40=
87+
github.com/sqlc-dev/zetajones v0.1.0/go.mod h1:dU1DxwqC6Cahbpnw16KpH1J2waWRDMdwyDSvovMZR4I=
8688
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8789
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
8890
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

internal/cmd/parse.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
1212
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
13+
"github.com/sqlc-dev/sqlc/internal/engine/googlesql"
1314
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1415
"github.com/sqlc-dev/sqlc/internal/engine/sqlite"
1516
"github.com/sqlc-dev/sqlc/internal/sql/ast"
@@ -31,15 +32,18 @@ Examples:
3132
sqlc parse --dialect sqlite queries.sql
3233
3334
# Parse ClickHouse SQL
34-
sqlc parse --dialect clickhouse queries.sql`,
35+
sqlc parse --dialect clickhouse queries.sql
36+
37+
# Parse GoogleSQL (BigQuery, Spanner)
38+
sqlc parse --dialect googlesql queries.sql`,
3539
Args: cobra.MaximumNArgs(1),
3640
RunE: func(cmd *cobra.Command, args []string) error {
3741
dialect, err := cmd.Flags().GetString("dialect")
3842
if err != nil {
3943
return err
4044
}
4145
if dialect == "" {
42-
return fmt.Errorf("--dialect flag is required (postgresql, mysql, sqlite, or clickhouse)")
46+
return fmt.Errorf("--dialect flag is required (postgresql, mysql, sqlite, clickhouse, or googlesql)")
4347
}
4448

4549
// Determine input source
@@ -78,8 +82,11 @@ Examples:
7882
case "clickhouse":
7983
parser := clickhouse.NewParser()
8084
stmts, err = parser.Parse(input)
85+
case "googlesql":
86+
parser := googlesql.NewParser()
87+
stmts, err = parser.Parse(input)
8188
default:
82-
return fmt.Errorf("unsupported dialect: %s (use postgresql, mysql, sqlite, or clickhouse)", dialect)
89+
return fmt.Errorf("unsupported dialect: %s (use postgresql, mysql, sqlite, clickhouse, or googlesql)", dialect)
8390
}
8491
if err != nil {
8592
return fmt.Errorf("parse error: %w", err)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package googlesql
2+
3+
import (
4+
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
5+
)
6+
7+
func NewCatalog() *catalog.Catalog {
8+
def := "main" // GoogleSQL has no implicit schema; use "main" as the default
9+
return &catalog.Catalog{
10+
DefaultSchema: def,
11+
Schemas: []*catalog.Schema{
12+
defaultSchema(def),
13+
},
14+
Extensions: map[string]struct{}{},
15+
}
16+
}

0 commit comments

Comments
 (0)