Skip to content

Commit

Permalink
Support more integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Apr 6, 2024
1 parent 2f74eb6 commit eeb9377
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/cdc/util/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit eeb9377

Please sign in to comment.