mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix(database/gdb): clickhouse can not support int128/int256/uint128/uint256 (#4370)
When use clickhouse and use field type int128/int256/uint128/uint256. It can not work well and it will return 0 value. Add the new field types to let it work well. By the way, the data struct field need be set to big.Int when use the types.
This commit is contained in:
@ -786,6 +786,7 @@ const (
|
||||
LocalTypeUint LocalType = "uint"
|
||||
LocalTypeInt64 LocalType = "int64"
|
||||
LocalTypeUint64 LocalType = "uint64"
|
||||
LocalTypeBigInt LocalType = "bigint"
|
||||
LocalTypeIntSlice LocalType = "[]int"
|
||||
LocalTypeInt64Slice LocalType = "[]int64"
|
||||
LocalTypeUint64Slice LocalType = "[]uint64"
|
||||
@ -817,6 +818,10 @@ const (
|
||||
fieldTypeBigInt = "big_int"
|
||||
fieldTypeBigint = "bigint"
|
||||
fieldTypeBigserial = "bigserial"
|
||||
fieldTypeInt128 = "int128"
|
||||
fieldTypeInt256 = "int256"
|
||||
fieldTypeUint128 = "uint128"
|
||||
fieldTypeUint256 = "uint256"
|
||||
fieldTypeReal = "real"
|
||||
fieldTypeFloat = "float"
|
||||
fieldTypeDouble = "double"
|
||||
|
||||
@ -9,6 +9,7 @@ package gdb
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@ -282,6 +283,13 @@ func (c *Core) CheckLocalTypeForField(ctx context.Context, fieldType string, _ i
|
||||
}
|
||||
return LocalTypeInt64, nil
|
||||
|
||||
case
|
||||
fieldTypeInt128,
|
||||
fieldTypeInt256,
|
||||
fieldTypeUint128,
|
||||
fieldTypeUint256:
|
||||
return LocalTypeBigInt, nil
|
||||
|
||||
case
|
||||
fieldTypeReal:
|
||||
return LocalTypeFloat32, nil
|
||||
@ -408,6 +416,16 @@ func (c *Core) ConvertValueForLocal(
|
||||
case LocalTypeUint64Bytes:
|
||||
return gbinary.BeDecodeToUint64(gconv.Bytes(fieldValue)), nil
|
||||
|
||||
case LocalTypeBigInt:
|
||||
switch v := fieldValue.(type) {
|
||||
case big.Int:
|
||||
return v.String(), nil
|
||||
case *big.Int:
|
||||
return v.String(), nil
|
||||
default:
|
||||
return gconv.String(fieldValue), nil
|
||||
}
|
||||
|
||||
case LocalTypeFloat32:
|
||||
return gconv.Float32(gconv.String(fieldValue)), nil
|
||||
|
||||
|
||||
Reference in New Issue
Block a user