Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
optimize clickhouse decimal casting [nt]
Browse files Browse the repository at this point in the history
  • Loading branch information
flarco committed Jan 19, 2024
1 parent eb1465b commit cf4d4dd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions database/database_clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,18 @@ func (conn *ClickhouseConn) BulkImportStream(tableFName string, ds *iop.Datastre
return g.Error(err, "could not prepare statement")
}

decimalCols := []int{}
for i, col := range batch.Columns {
if col.Type.IsDecimal() {
decimalCols = append(decimalCols, i)
}
}

for row := range batch.Rows {
// set decimals correctly
for i, col := range batch.Columns {
if col.Type.IsDecimal() {
if val, err := decimal.NewFromString(cast.ToString(row[i])); err == nil {
row[i] = val
}
for _, colI := range decimalCols {
if val, err := decimal.NewFromString(cast.ToString(row[colI])); err == nil {
row[colI] = val
}
}

Expand Down

0 comments on commit cf4d4dd

Please sign in to comment.