From bec98e8de09e91c82073a3e29ba3716732477308 Mon Sep 17 00:00:00 2001 From: Hunk Zhu <54zhua@gmail.com> Date: Fri, 22 Aug 2025 22:05:15 +0800 Subject: [PATCH] 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. --- database/gdb/gdb.go | 5 +++++ database/gdb/gdb_core_structure.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 08bad34e2..ff8457656 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -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" diff --git a/database/gdb/gdb_core_structure.go b/database/gdb/gdb_core_structure.go index 0ec291a2f..05e09f02d 100644 --- a/database/gdb/gdb_core_structure.go +++ b/database/gdb/gdb_core_structure.go @@ -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