Skip to content

Commit 5112bab

Browse files
committed
Register ClickHouse engine in compiler
Add engine registration in compiler pipeline and configuration schema. Enables compiler to recognize and process ClickHouse engine configurations.
1 parent 7960b17 commit 5112bab

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

internal/compiler/engine.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ import (
77
"github.com/sqlc-dev/sqlc/internal/analyzer"
88
"github.com/sqlc-dev/sqlc/internal/config"
99
"github.com/sqlc-dev/sqlc/internal/dbmanager"
10+
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
1011
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
1112
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1213
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
1314
"github.com/sqlc-dev/sqlc/internal/engine/sqlite"
1415
sqliteanalyze "github.com/sqlc-dev/sqlc/internal/engine/sqlite/analyzer"
1516
"github.com/sqlc-dev/sqlc/internal/opts"
17+
"github.com/sqlc-dev/sqlc/internal/sql/ast"
1618
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
1719
)
1820

21+
type ResolveTypeFunc func(call *ast.FuncCall, fun *catalog.Function, resolve func(n ast.Node) (*catalog.Column, error)) *ast.TypeName
22+
1923
type Compiler struct {
2024
conf config.SQL
2125
combo config.CombinedSettings
@@ -26,7 +30,8 @@ type Compiler struct {
2630
client dbmanager.Client
2731
selector selector
2832

29-
schema []string
33+
schema []string
34+
TypeResolver ResolveTypeFunc
3035
}
3136

3237
func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, error) {
@@ -38,6 +43,11 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
3843
}
3944

4045
switch conf.Engine {
46+
case config.EngineClickHouse:
47+
c.parser = clickhouse.NewParser()
48+
c.catalog = clickhouse.NewCatalog()
49+
c.selector = newDefaultSelector()
50+
c.TypeResolver = clickhouse.TypeResolver
4151
case config.EngineSQLite:
4252
c.parser = sqlite.NewParser()
4353
c.catalog = sqlite.NewCatalog()
@@ -79,7 +89,15 @@ func (c *Compiler) Catalog() *catalog.Catalog {
7989
}
8090

8191
func (c *Compiler) ParseCatalog(schema []string) error {
82-
return c.parseCatalog(schema)
92+
err := c.parseCatalog(schema)
93+
if err == nil && c.conf.Engine == config.EngineClickHouse {
94+
// Set the catalog on the ClickHouse parser so it can register
95+
// context-dependent functions during query parsing
96+
if chParser, ok := c.parser.(*clickhouse.Parser); ok {
97+
chParser.Catalog = c.catalog
98+
}
99+
}
100+
return err
83101
}
84102

85103
func (c *Compiler) ParseQueries(queries []string, o opts.Parser) error {

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error {
5151
}
5252

5353
const (
54+
EngineClickHouse Engine = "clickhouse"
5455
EngineMySQL Engine = "mysql"
5556
EnginePostgreSQL Engine = "postgresql"
5657
EngineSQLite Engine = "sqlite"

internal/config/v_one.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"properties": {
3434
"engine": {
3535
"enum": [
36+
"clickhouse",
3637
"postgresql",
3738
"mysql",
3839
"sqlite"
@@ -192,6 +193,7 @@
192193
},
193194
"engine": {
194195
"enum": [
196+
"clickhouse",
195197
"postgresql",
196198
"mysql",
197199
"sqlite"
@@ -300,6 +302,7 @@
300302
},
301303
"engine": {
302304
"enum": [
305+
"clickhouse",
303306
"postgresql",
304307
"mysql",
305308
"sqlite"

internal/config/v_two.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"engine": {
3838
"enum": [
39+
"clickhouse",
3940
"postgresql",
4041
"mysql",
4142
"sqlite"
@@ -201,6 +202,7 @@
201202
},
202203
"engine": {
203204
"enum": [
205+
"clickhouse",
204206
"postgresql",
205207
"mysql",
206208
"sqlite"
@@ -358,6 +360,7 @@
358360
},
359361
"engine": {
360362
"enum": [
363+
"clickhouse",
361364
"postgresql",
362365
"mysql",
363366
"sqlite"

0 commit comments

Comments
 (0)