From 42acf53540ddd890e74d3426df8599d383671773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Egelund-M=C3=BCller?= Date: Fri, 23 Aug 2024 11:38:53 +0100 Subject: [PATCH] Runtime: Cast DECIMALs from ClickHouse to floats in APIs --- runtime/pkg/jsonval/jsonval.go | 8 ++++++++ runtime/pkg/pbutil/pbutil.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/runtime/pkg/jsonval/jsonval.go b/runtime/pkg/jsonval/jsonval.go index 4a617e36780..80958c065f3 100644 --- a/runtime/pkg/jsonval/jsonval.go +++ b/runtime/pkg/jsonval/jsonval.go @@ -57,6 +57,14 @@ func ToValue(v any, t *runtimev1.Type) (any, error) { } return v, nil case string: + if t != nil && t.Code == runtimev1.Type_CODE_DECIMAL { + // Evil cast to float until frontend can deal with bigs: + v2, ok := new(big.Float).SetString(v) + if ok { + f, _ := v2.Float64() + return f, nil + } + } return strings.ToValidUTF8(v, "�"), nil case []byte: if t != nil && t.Code == runtimev1.Type_CODE_UUID { diff --git a/runtime/pkg/pbutil/pbutil.go b/runtime/pkg/pbutil/pbutil.go index 4057f75feb9..ab86f1cf289 100644 --- a/runtime/pkg/pbutil/pbutil.go +++ b/runtime/pkg/pbutil/pbutil.go @@ -116,6 +116,14 @@ func ToValue(v any, t *runtimev1.Type) (*structpb.Value, error) { } } case string: + if t != nil && t.Code == runtimev1.Type_CODE_DECIMAL { + // Evil cast to float until frontend can deal with bigs: + v2, ok := new(big.Float).SetString(v) + if ok { + f, _ := v2.Float64() + return structpb.NewNumberValue(f), nil + } + } return structpb.NewStringValue(strings.ToValidUTF8(v, "�")), nil case net.IP: return structpb.NewStringValue(v.String()), nil