Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: clickhouse engine #3294

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/AfterShip/clickhouse-sql-parser v0.3.3 // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/AfterShip/clickhouse-sql-parser v0.3.3 h1:06Thdd8RMASiyP25YkjYrNzwGKen9bc2Yj5ZSjlSnBc=
github.com/AfterShip/clickhouse-sql-parser v0.3.3/go.mod h1:W0Z82wJWkJxz2RVun/RMwxue3g7ut47Xxl+SFqdJGus=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.C
return nil, true
}
if err := c.ParseCatalog(sql.Schema); err != nil {
fmt.Fprintf(stderr, "# package %s\n", name)
fmt.Fprintf(stderr, "# parsing catalog: package %s\n", name)
if parserErr, ok := err.(*multierr.Error); ok {
for _, fileErr := range parserErr.Errs() {
printFileErr(stderr, dir, fileErr)
Expand All @@ -320,7 +320,7 @@ func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.C
debug.Dump(c.Catalog())
}
if err := c.ParseQueries(sql.Queries, parserOpts); err != nil {
fmt.Fprintf(stderr, "# package %s\n", name)
fmt.Fprintf(stderr, "# parsing queries: package %s\n", name)
if parserErr, ok := err.(*multierr.Error); ok {
for _, fileErr := range parserErr.Errs() {
printFileErr(stderr, dir, fileErr)
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
// SQLite really doesn't want us to depend on the output of EXPLAIN
// QUERY PLAN: https://www.sqlite.org/eqp.html
expl = nil
case config.EngineClickhouse:
// TODO(clickhouse): ch-toko
panic("not implemented(ch-todo)")
default:
return fmt.Errorf("unsupported database uri: %s", s.Engine)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/sqlc-dev/sqlc/internal/analyzer"
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
Expand Down Expand Up @@ -40,6 +41,9 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
}

switch conf.Engine {
case config.EngineClickhouse:
c.parser = clickhouse.NewParser()
c.catalog = clickhouse.NewCatalog()
case config.EngineSQLite:
c.parser = sqlite.NewParser()
c.catalog = sqlite.NewCatalog()
Expand Down Expand Up @@ -69,6 +73,7 @@ func (c *Compiler) Catalog() *catalog.Catalog {
}

func (c *Compiler) ParseCatalog(schema []string) error {

return c.parseCatalog(schema)
}

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
EngineMySQL Engine = "mysql"
EnginePostgreSQL Engine = "postgresql"
EngineSQLite Engine = "sqlite"
EngineClickhouse Engine = "clickhouse"
)

type Config struct {
Expand Down
16 changes: 16 additions & 0 deletions internal/engine/clickhouse/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package clickhouse

import "github.com/sqlc-dev/sqlc/internal/sql/catalog"

func NewCatalog() *catalog.Catalog {
def := ""
c := &catalog.Catalog{
DefaultSchema: def,
Schemas: []*catalog.Schema{
&catalog.Schema{Name: ""},
},
Extensions: map[string]struct{}{},
}
c.Schemas = append(c.Schemas, getInformationSchema())
return c
}
12 changes: 12 additions & 0 deletions internal/engine/clickhouse/information_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package clickhouse

import "github.com/sqlc-dev/sqlc/internal/sql/catalog"

func getInformationSchema() *catalog.Schema {
s := &catalog.Schema{Name: "information_schema"}
s.Funcs = make([]*catalog.Function, 0)
s.Tables = []*catalog.Table{
//TODO
}
return s
}
Loading
Loading