From eeb93778220c3b554aa5f48c7c8dc2f011334203 Mon Sep 17 00:00:00 2001 From: Nathan Villaescusa Date: Sat, 6 Apr 2024 02:06:41 -0700 Subject: [PATCH] Support more integer types --- lib/cdc/util/parse.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/cdc/util/parse.go b/lib/cdc/util/parse.go index a0809b463..fc56a08e3 100644 --- a/lib/cdc/util/parse.go +++ b/lib/cdc/util/parse.go @@ -15,12 +15,21 @@ func parseField(field debezium.Field, value any) (any, error) { // Check if the field is an integer and requires us to cast it as such. if field.IsInteger() { - valFloat, isOk := value.(float64) - if !isOk { - return nil, fmt.Errorf("failed to cast value to float64") + switch typedValue := value.(type) { + case int: + return int64(typedValue), nil + case int16: + return int64(typedValue), nil + case int32: + return int64(typedValue), nil + case int64: + return typedValue, nil + case float64: + // The JSON encoding and decoding process converts all integers to float64. + return int64(typedValue), nil + default: + return nil, fmt.Errorf("unsupported integer type: %T", value) } - - return int(valFloat), nil } if valid, supportedType := debezium.RequiresSpecialTypeCasting(field.DebeziumType); valid {