Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Nov 22, 2024
1 parent 4344149 commit 2dfa5ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
21 changes: 21 additions & 0 deletions lib/debezium/converters/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,24 @@ func (Float64) Convert(value any) (any, error) {
return nil, fmt.Errorf("unexpected type %T", value)
}
}

type Array struct{}

func (Array) ToKindDetails() typing.KindDetails {
return typing.Array
}

func (Array) Convert(value any) (any, error) {
if casted, isOk := value.([]string); isOk {
// Filter TOASTED array
if len(casted) == 1 {
if casted[0] == constants.ToastUnavailableValuePlaceholder {
return constants.ToastUnavailableValuePlaceholder, nil
}

return casted, nil
}
}

return value, nil
}
15 changes: 15 additions & 0 deletions lib/debezium/converters/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ func TestFloat64_Convert(t *testing.T) {
}
}
}

func TestArray_Convert(t *testing.T) {
{
// Valid
value, err := Array{}.Convert([]int{1, 2, 3})
assert.NoError(t, err)
assert.Equal(t, []int{1, 2, 3}, value)
}
{
// Filter TOASTED value
value, err := Array{}.Convert([]string{"__debezium_unavailable_value"})
assert.NoError(t, err)
assert.Equal(t, "__debezium_unavailable_value", value)
}
}
4 changes: 2 additions & 2 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func (f Field) ToValueConverter() (converters.ValueConverter, error) {
switch f.Type {
case Double, Float:
return converters.Float64{}, nil
case Array:
return converters.Array{}, nil
}

return nil, nil
Expand Down Expand Up @@ -167,8 +169,6 @@ func (f Field) ToKindDetails() (typing.KindDetails, error) {
return typing.Struct, nil
case Boolean:
return typing.Boolean, nil
case Array:
return typing.Array, nil
default:
return typing.Invalid, fmt.Errorf("unhandled field type %q", f.Type)
}
Expand Down

0 comments on commit 2dfa5ac

Please sign in to comment.