Skip to content

Commit

Permalink
use literals in distributed engine definition in ch (#6446)
Browse files Browse the repository at this point in the history
* use literals in distributed engine definition in ch

* do not quote db

* use safe sql string

* quote database
  • Loading branch information
pjain1 authored Jan 18, 2025
1 parent 77b00c0 commit 298f5ea
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions runtime/drivers/clickhouse/olap.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ func (c *connection) createTable(ctx context.Context, name, sql string, outputPr
}
// create the distributed table
var distributed strings.Builder
database := c.config.Database
if c.config.Database == "" {
database = "currentDatabase()"
database := "currentDatabase()"
if c.config.Database != "" {
database = safeSQLString(c.config.Database)
}
fmt.Fprintf(&distributed, "CREATE OR REPLACE TABLE %s %s AS %s", safeSQLName(name), onClusterClause, safelocalTableName(name))
fmt.Fprintf(&distributed, " ENGINE = Distributed(%s, %s, %s", safeSQLName(c.config.Cluster), database, safelocalTableName(name))
fmt.Fprintf(&distributed, " ENGINE = Distributed(%s, %s, %s", safeSQLString(c.config.Cluster), database, safeSQLString(localTableName(name)))
if outputProps.DistributedShardingKey != "" {
fmt.Fprintf(&distributed, ", %s", outputProps.DistributedShardingKey)
} else {
Expand Down Expand Up @@ -1192,3 +1192,7 @@ func localTableName(name string) string {
func tempTableForDictionary(name string) string {
return name + "_dict_temp_"
}

func safeSQLString(name string) string {
return drivers.DialectClickHouse.EscapeStringValue(name)
}

0 comments on commit 298f5ea

Please sign in to comment.