Skip to content

Commit

Permalink
clickhouse: at least backtick identifiers
Browse files Browse the repository at this point in the history
Long term we should be correctly escaping identifiers with backticks
  • Loading branch information
serprex committed Feb 12, 2024
1 parent 29b65d4 commit 8a22811
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *ClickhouseConnector) NormalizeRecords(ctx context.Context, req *model.N
cn := column.Name
ct := column.Type

colSelector.WriteString(fmt.Sprintf("%s,", cn))
colSelector.WriteString(fmt.Sprintf("`%s`,", cn))
colType := qvalue.QValueKind(ct)
clickhouseType, err := qValueKindToClickhouseType(colType)
if err != nil {
Expand All @@ -161,15 +161,15 @@ func (c *ClickhouseConnector) NormalizeRecords(ctx context.Context, req *model.N
clickhouseType = "String"
}

projection.WriteString(fmt.Sprintf("JSONExtract(_peerdb_data, '%s', '%s') AS %s, ", cn, clickhouseType, cn))
projection.WriteString(fmt.Sprintf("JSONExtract(_peerdb_data, '%s', '%s') AS `%s`,", cn, clickhouseType, cn))
}

// add _peerdb_sign as _peerdb_record_type / 2
projection.WriteString(fmt.Sprintf("intDiv(_peerdb_record_type, 2) AS %s, ", signColName))
projection.WriteString(fmt.Sprintf("intDiv(_peerdb_record_type, 2) AS `%s`,", signColName))
colSelector.WriteString(fmt.Sprintf("%s,", signColName))

// add _peerdb_timestamp as _peerdb_version
projection.WriteString(fmt.Sprintf("_peerdb_timestamp AS %s", versionColName))
projection.WriteString(fmt.Sprintf("_peerdb_timestamp AS `%s`", versionColName))
colSelector.WriteString(versionColName)
colSelector.WriteString(") ")

Expand Down

0 comments on commit 8a22811

Please sign in to comment.