Skip to content

Commit acff325

Browse files
committed
clickhouse: expose core analysis via sqlc analyze, drop codegen
Wire the ClickHouse engine into `sqlc analyze` so the core catalog and analyzer can be exercised end to end without committing to code generation yet. The analyze command builds the compiler, applies the schema DDL to the core catalog, and reports inferred result columns as JSON — the same static-analysis path `generate` would use. Remove the not-yet-ready code generation surface: the ClickHouse Go type map, the core-catalog to plugin.Catalog projection, and the generate golden test. ClickHouse type inference is now covered by an analyze_basic end-to-end case, matching how the other engines are tested.
1 parent 13790dc commit acff325

16 files changed

Lines changed: 62 additions & 229 deletions

File tree

docs/howto/analyze.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ provided. The schema is always read from the `--schema` file.
1818

1919
## Flags
2020

21-
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`, or
22-
`sqlite`. Required.
21+
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`,
22+
`sqlite`, or `clickhouse`. Required.
2323
- `--schema`, `-s` - Path to the schema (DDL) file. Required.
2424
- `--ast` - Include each statement's AST in the output. Defaults to `false`.
2525

internal/cmd/analyze.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Examples:
3737
# Analyze a SQLite query
3838
sqlc analyze --dialect sqlite --schema schema.sql query.sql
3939
40+
# Analyze a ClickHouse query
41+
sqlc analyze --dialect clickhouse --schema schema.sql query.sql
42+
4043
# Analyze a query piped via stdin
4144
echo "-- name: GetAuthor :one
4245
SELECT * FROM authors WHERE id = $1;" | sqlc analyze --dialect postgresql --schema schema.sql
@@ -50,7 +53,7 @@ Examples:
5053
return err
5154
}
5255
if dialect == "" {
53-
return fmt.Errorf("--dialect flag is required (postgresql, mysql, or sqlite)")
56+
return fmt.Errorf("--dialect flag is required (postgresql, mysql, sqlite, or clickhouse)")
5457
}
5558

5659
schemaPath, err := cmd.Flags().GetString("schema")
@@ -107,8 +110,10 @@ Examples:
107110
engine = config.EngineMySQL
108111
case "sqlite":
109112
engine = config.EngineSQLite
113+
case "clickhouse":
114+
engine = config.EngineClickHouse
110115
default:
111-
return fmt.Errorf("unsupported dialect: %s (use postgresql, mysql, or sqlite)", dialect)
116+
return fmt.Errorf("unsupported dialect: %s (use postgresql, mysql, sqlite, or clickhouse)", dialect)
112117
}
113118

114119
sql := config.SQL{
@@ -150,7 +155,7 @@ Examples:
150155
return nil
151156
},
152157
}
153-
cmd.Flags().StringP("dialect", "d", "", "SQL dialect to use (postgresql, mysql, or sqlite)")
158+
cmd.Flags().StringP("dialect", "d", "", "SQL dialect to use (postgresql, mysql, sqlite, or clickhouse)")
154159
cmd.Flags().StringP("schema", "s", "", "path to the schema file")
155160
cmd.Flags().BoolP("ast", "", false, "include the statement AST in the output")
156161
return cmd

internal/cmd/shim.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/sqlc-dev/sqlc/internal/compiler"
55
"github.com/sqlc-dev/sqlc/internal/config"
66
"github.com/sqlc-dev/sqlc/internal/config/convert"
7-
coreshim "github.com/sqlc-dev/sqlc/internal/core/shim"
87
"github.com/sqlc-dev/sqlc/internal/info"
98
"github.com/sqlc-dev/sqlc/internal/plugin"
109
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
@@ -225,15 +224,9 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {
225224
}
226225

227226
func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.GenerateRequest {
228-
var cat *plugin.Catalog
229-
if r.CoreCatalog != nil {
230-
cat = coreshim.PluginCatalog(r.CoreCatalog)
231-
} else {
232-
cat = pluginCatalog(r.Catalog)
233-
}
234227
return &plugin.GenerateRequest{
235228
Settings: pluginSettings(r, settings),
236-
Catalog: cat,
229+
Catalog: pluginCatalog(r.Catalog),
237230
Queries: pluginQueries(r),
238231
SqlcVersion: info.Version,
239232
}

internal/codegen/golang/clickhouse_type.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

internal/codegen/golang/go_type.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ func goInnerType(req *plugin.GenerateRequest, options *opts.Options, col *plugin
8686
return postgresType(req, options, col)
8787
case "sqlite":
8888
return sqliteType(req, options, col)
89-
case "clickhouse":
90-
return clickhouseType(req, options, col)
9189
default:
9290
return "interface{}"
9391
}

internal/compiler/compile.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) {
146146
}
147147

148148
return &Result{
149-
Catalog: c.catalog,
150-
CoreCatalog: c.coreCatalog,
151-
Queries: q,
149+
Catalog: c.catalog,
150+
Queries: q,
152151
}, nil
153152
}

internal/compiler/result.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package compiler
22

33
import (
4-
"github.com/sqlc-dev/sqlc/internal/core"
54
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
65
)
76

87
type Result struct {
98
Catalog *catalog.Catalog
109
Queries []*Query
11-
12-
CoreCatalog *core.Catalog
1310
}

internal/core/shim/shim.go

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"command": "analyze",
3+
"args": ["--dialect", "clickhouse", "--schema", "schema.sql", "query.sql"],
4+
"contexts": ["base"]
5+
}

internal/endtoend/testdata/clickhouse_select/clickhouse/query.sql renamed to internal/endtoend/testdata/analyze_basic/clickhouse/query.sql

File renamed without changes.

0 commit comments

Comments
 (0)