@@ -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+
1923type 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
3237func 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
8191func (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
85103func (c * Compiler ) ParseQueries (queries []string , o opts.Parser ) error {
0 commit comments