Skip to content

Commit 59e579d

Browse files
kyleconroyclaude
andcommitted
clickhouse/core: strip comments and remove xqlc references
Remove comments from the Go files authored for this work (catalog core, analyzer, ClickHouse engine, compile path, codegen type map) and drop the comments added to the files touched along the way, keeping //go:generate and //go:embed directives. No remaining references to xqlc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XTGxNHW6v1S1YyC9FDSgrK
1 parent 0e69c04 commit 59e579d

33 files changed

Lines changed: 39 additions & 444 deletions

internal/cmd/shim.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {
225225
}
226226

227227
func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.GenerateRequest {
228-
// Engines on the xqlc core (ClickHouse) project the codegen catalog
229-
// from the core catalog rather than the in-memory sql/catalog, which is
230-
// nil on that path.
231228
var cat *plugin.Catalog
232229
if r.CoreCatalog != nil {
233230
cat = pluginCatalogFromCore(r.CoreCatalog)
@@ -242,12 +239,6 @@ func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugi
242239
}
243240
}
244241

245-
// pluginCatalogFromCore projects a core.Catalog (the xqlc SQLite-backed
246-
// catalog) into the plugin.Catalog that codegen consumes to emit models
247-
// and enums. It reads through the catalog's typed accessors, which are
248-
// backed by sqlc-generated queries. Projection is best-effort: an
249-
// unexpected error against the in-memory catalog yields a partial catalog
250-
// rather than aborting generation.
251242
func pluginCatalogFromCore(cc *core.Catalog) *plugin.Catalog {
252243
var schemas []*plugin.Schema
253244

internal/codegen/golang/clickhouse_type.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
"github.com/sqlc-dev/sqlc/internal/plugin"
99
)
1010

11-
// clickhouseType maps a ClickHouse column type to a Go type. Type names
12-
// arrive lower-cased from the core catalog (e.g. "uint64", "string",
13-
// "datetime"). Nullable columns (NotNull == false) map to a pointer, which
14-
// is how the clickhouse-go driver represents Nullable(T).
1511
func clickhouseType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
1612
dt := strings.ToLower(sdk.DataType(col.Type))
1713
notNull := col.NotNull
@@ -34,7 +30,6 @@ func clickhouseType(req *plugin.GenerateRequest, options *opts.Options, col *plu
3430
case "int64":
3531
return nullable(notNull, "int64")
3632
case "uint128", "uint256", "int128", "int256":
37-
// Big integers are represented as *big.Int by clickhouse-go.
3833
return "*big.Int"
3934
case "float32", "bfloat16":
4035
return nullable(notNull, "float32")
@@ -47,9 +42,6 @@ func clickhouseType(req *plugin.GenerateRequest, options *opts.Options, col *plu
4742
case "date", "date32", "datetime", "datetime64":
4843
return nullable(notNull, "time.Time")
4944

50-
// The following resolve to string for now; richer mappings
51-
// (decimal.Decimal, uuid.UUID, netip.Addr, json.RawMessage) require
52-
// wiring their imports into the Go importer and are a follow-up.
5345
case "decimal", "decimal32", "decimal64", "decimal128", "decimal256",
5446
"uuid", "ipv4", "ipv6", "json", "enum8", "enum16":
5547
return nullable(notNull, "string")
@@ -59,7 +51,6 @@ func clickhouseType(req *plugin.GenerateRequest, options *opts.Options, col *plu
5951
}
6052
}
6153

62-
// nullable wraps a base Go type in a pointer when the column is nullable.
6354
func nullable(notNull bool, base string) string {
6455
if notNull {
6556
return base

internal/compiler/compile.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ func (c *Compiler) parseCatalog(schemas []string) error {
5656
continue
5757
}
5858

59-
// ClickHouse populates the core catalog instead of the in-memory
60-
// sql/catalog.
6159
if c.coreCatalog != nil {
6260
for i := range stmts {
6361
if err := clickhouse.Apply(c.coreCatalog, stmts[i].Raw); err != nil {

internal/compiler/engine.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ type Compiler struct {
2929
client dbmanager.Client
3030
selector selector
3131

32-
// coreCatalog is the xqlc-derived catalog used by engines whose
33-
// analysis runs on the core analyzer (currently ClickHouse) instead of
34-
// the legacy compiler analyze step. It is nil for other engines.
3532
coreCatalog *core.Catalog
3633

3734
schema []string
@@ -119,9 +116,6 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings, parserOpts opts
119116
}
120117
}
121118
case config.EngineClickHouse:
122-
// ClickHouse runs on the xqlc analysis core: its schema and queries
123-
// are resolved against a core.Catalog by the core analyzer, not the
124-
// legacy compiler analyze step or the in-memory sql/catalog.
125119
c.parser = clickhouse.NewParser()
126120
c.selector = newDefaultSelector()
127121
cat, err := core.New(clickhouse.Dialect())

internal/compiler/parse.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
var debugDumpAST = sqlcdebug.New("dumpast")
2020

2121
func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query, error) {
22-
// ClickHouse resolves types through the core analyzer, entirely
23-
// bypassing the legacy analyze step below.
2422
if c.coreCatalog != nil {
2523
return c.parseQueryCore(stmt, src)
2624
}

internal/compiler/parse_clickhouse.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ import (
1212
"github.com/sqlc-dev/sqlc/internal/sql/validate"
1313
)
1414

15-
// parseQueryCore is the analysis path for engines backed by the xqlc core
16-
// catalog and analyzer (currently ClickHouse). It reuses the shared,
17-
// engine-agnostic query-metadata parsing but resolves columns and
18-
// parameters through core/analyzer, never touching the legacy compiler
19-
// analyze step (inferQuery/outputColumns/parameters) or the
20-
// analyzer.Analyzer seam.
2115
func (c *Compiler) parseQueryCore(stmt ast.Node, src string) (*Query, error) {
2216
raw, ok := stmt.(*ast.RawStmt)
2317
if !ok {
@@ -54,9 +48,6 @@ func (c *Compiler) parseQueryCore(stmt ast.Node, src string) (*Query, error) {
5448

5549
var cols []*Column
5650
var params []Parameter
57-
// Only result-shaped statements produce columns/parameters. Non-SELECT
58-
// statements (:exec, DDL) currently yield an empty shape; growing the
59-
// core analyzer to cover INSERT/UPDATE/DELETE is a follow-up.
6051
if _, ok := raw.Stmt.(*ast.SelectStmt); ok {
6152
res, err := coreanalyzer.Prepare(c.coreCatalog, raw)
6253
if err != nil {
@@ -91,9 +82,6 @@ func (c *Compiler) parseQueryCore(stmt ast.Node, src string) (*Query, error) {
9182
}, nil
9283
}
9384

94-
// coreColumn maps a core.Column (analyzer output) onto the compiler's
95-
// Column. The type name is carried in DataType; Type is left nil so the
96-
// codegen shim uses DataType directly.
9785
func coreColumn(c core.Column) *Column {
9886
col := &Column{
9987
Name: c.Name,

internal/compiler/result.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ type Result struct {
99
Catalog *catalog.Catalog
1010
Queries []*Query
1111

12-
// CoreCatalog, when set, is the xqlc-derived catalog that drives both
13-
// analysis and codegen for engines on the core (currently ClickHouse).
14-
// When it is non-nil, codegen projects the catalog from it instead of
15-
// from Catalog.
1612
CoreCatalog *core.Catalog
1713
}

internal/core/analysis.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package core
22

3-
// Command identifies the kind of statement that produced a PrepareResult.
4-
// Only the four DML statements that can have a prepare-able shape are
5-
// emitted; DDL and TCL produce an empty result with Command == "".
63
type Command string
74

85
const (
@@ -12,40 +9,19 @@ const (
129
CommandDelete Command = "DELETE"
1310
)
1411

15-
// PrepareResult describes the output of preparing a SQL statement.
1612
type PrepareResult struct {
1713
Command Command `json:"command,omitempty"`
1814
Columns []Column `json:"columns"`
1915
Parameters []Parameter `json:"parameters"`
2016
}
2117

22-
// ColumnSource identifies the table column a result column or bind
23-
// parameter is sourced from. All fields are optional; the struct is
24-
// emitted only when at least one is populated.
25-
//
26-
// Schema / Table / Column are the *origin* identifiers (pre-alias) —
27-
// they correspond to sqlite's `sqlite3_column_origin_name` and mysql's
28-
// `org_table` / `org_name`. TableAlias is the name the query used to
29-
// refer to the table; it lets codegen distinguish `t1` from `t2` in
30-
// `SELECT t1.x, t2.x FROM t t1 JOIN t t2 ...`.
3118
type ColumnSource struct {
3219
Schema string `json:"schema,omitempty"`
3320
Table string `json:"table,omitempty"`
3421
TableAlias string `json:"table_alias,omitempty"`
3522
Column string `json:"column,omitempty"`
3623
}
3724

38-
// Column describes a single output column from a prepared statement.
39-
//
40-
// SourceClassOID and SourceAttributeOID are populated when the column
41-
// is a direct reference to a table column (i.e. it appears in
42-
// sql_attribute); they are zero for computed/derived expressions like
43-
// aggregates or arithmetic. Source is the human-readable resolution of
44-
// those OIDs and is populated under the same conditions.
45-
//
46-
// DeclType, TypeLength, TypeScale, IsPrimaryKey, IsUnique, and
47-
// IsAutoIncrement come from the resolved source attribute and are zero
48-
// for computed expressions.
4925
type Column struct {
5026
Name string `json:"name"`
5127
DataType string `json:"data_type"`
@@ -62,15 +38,6 @@ type Column struct {
6238
IsAutoIncrement bool `json:"is_auto_increment,omitempty"`
6339
}
6440

65-
// Parameter describes a bind parameter in a prepared statement.
66-
//
67-
// Number is the 1-based position of the parameter as it appeared in the
68-
// source ($1, $2, ...). Name is populated for named-parameter dialects
69-
// or when a sqlc-style "-- name:" annotation gave the param a name; it
70-
// is empty otherwise. DataType / TypeOID / NotNull come from the
71-
// resolved usage site (an operator overload, function argument, etc.).
72-
// Source identifies the column the parameter binds against (e.g.
73-
// `users.age` for `WHERE age > $1`), when one can be inferred.
7441
type Parameter struct {
7542
Number int `json:"number"`
7643
Name string `json:"name,omitempty"`

internal/core/analyzer/analyzer.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
// Package analyzer implements a dialect-neutral SQL query analyzer that
2-
// resolves names, types, operators, and parameters by querying the
3-
// catalog (core.Catalog). It produces a core.PrepareResult.
4-
//
5-
// Scope is intentionally narrow in this iteration: single-relation SELECT
6-
// queries, simple WHERE / GROUP BY / projection. JOINs, subqueries,
7-
// CTEs, set ops, and DML RETURNING are intended follow-ups.
81
package analyzer
92

103
import (
@@ -14,10 +7,6 @@ import (
147
"github.com/sqlc-dev/sqlc/internal/sql/ast"
158
)
169

17-
// Prepare walks a parsed statement and produces a PrepareResult by
18-
// querying the catalog for relations, types, operators, and casts.
19-
// stmt can be a *ast.RawStmt (typical parser output) or an unwrapped
20-
// statement node.
2110
func Prepare(cat *core.Catalog, stmt ast.Node) (core.PrepareResult, error) {
2211
if rs, ok := stmt.(*ast.RawStmt); ok {
2312
stmt = rs.Stmt
@@ -80,8 +69,6 @@ func (a *analyzer) analyzeSelect(s *ast.SelectStmt) error {
8069
}
8170
a.scope = sc
8271

83-
// Join ON conditions get typed against the (already-assembled)
84-
// scope so they can reference columns from either side.
8572
for _, item := range listItems(s.FromClause) {
8673
if err := a.typeJoinConditions(item); err != nil {
8774
return fmt.Errorf("join: %w", err)
@@ -129,9 +116,6 @@ func listItems(l *ast.List) []ast.Node {
129116
return l.Items
130117
}
131118

132-
// typeJoinConditions walks a FROM-list item and types every join's ON
133-
// expression. USING clauses are skipped — the columns they reference
134-
// already exist in scope, no expression to type.
135119
func (a *analyzer) typeJoinConditions(item ast.Node) error {
136120
je, ok := item.(*ast.JoinExpr)
137121
if !ok {

internal/core/analyzer/analyzer_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1010
)
1111

12-
// seedUsers builds a minimal catalog with a single "users" table so the
13-
// analyzer has something to resolve against. It deliberately avoids any
14-
// per-dialect seed: the point is to exercise the dialect-neutral
15-
// analyzer directly on sqlc's ast.
1612
func seedUsers(t *testing.T) *core.Catalog {
1713
t.Helper()
1814
cat, err := core.New()
@@ -46,9 +42,6 @@ func seedUsers(t *testing.T) *core.Catalog {
4642
return cat
4743
}
4844

49-
// prepare parses query with sqlc's own PostgreSQL parser — which emits
50-
// exactly the internal/sql/ast the analyzer was repointed onto — and
51-
// runs the analyzer against cat.
5245
func prepare(t *testing.T, cat *core.Catalog, query string) core.PrepareResult {
5346
t.Helper()
5447
stmts, err := postgresql.NewParser().Parse(strings.NewReader(query))

0 commit comments

Comments
 (0)