From cf4d4dd7395636afa317bffd2ce67b0f3f0f92cb Mon Sep 17 00:00:00 2001 From: Fritz Larco Date: Fri, 19 Jan 2024 07:27:52 -0300 Subject: [PATCH] optimize clickhouse decimal casting [nt] --- database/database_clickhouse.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/database/database_clickhouse.go b/database/database_clickhouse.go index 34070ac..e595206 100755 --- a/database/database_clickhouse.go +++ b/database/database_clickhouse.go @@ -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 } }