Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: Cast Clickhouse DECIMALs to floats in metrics APIs #5512

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions runtime/pkg/jsonval/jsonval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions runtime/pkg/pbutil/pbutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading