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:
Hunk Zhu
2025-08-22 22:05:15 +08:00
committed by GitHub
parent a6dbf4b7eb
commit bec98e8de0
2 changed files with 23 additions and 0 deletions

View File

@ -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"

View File

@ -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