Skip to content

Commit

Permalink
[Debezium] ItemsMetadata is optional (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Dec 12, 2024
1 parent 5b3ff02 commit d93bf20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Field struct {
DebeziumType SupportedDebeziumType `json:"name"`
Parameters map[string]any `json:"parameters"`
// [ItemsMetadata] is only populated if the literal type is an array.
ItemsMetadata Item `json:"items"`
ItemsMetadata *Item `json:"items,omitempty"`
}

func (f Field) GetScaleAndPrecision() (int32, *int32, error) {
Expand Down Expand Up @@ -146,7 +146,12 @@ func (f Field) ToValueConverter() (converters.ValueConverter, error) {

switch f.Type {
case Array:
return converters.NewArray(f.ItemsMetadata.DebeziumType == JSON), nil
var json bool
if f.ItemsMetadata != nil {
json = f.ItemsMetadata.DebeziumType == JSON
}

return converters.NewArray(json), nil
case Double, Float:
return converters.Float64{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/debezium/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestField_ParseValue(t *testing.T) {
}
{
// Array
field := Field{Type: Array, ItemsMetadata: Item{DebeziumType: JSON}}
field := Field{Type: Array, ItemsMetadata: &Item{DebeziumType: JSON}}
value, err := field.ParseValue([]any{`{"foo": "bar", "foo": "bar"}`, `{"hello": "world"}`})
assert.NoError(t, err)
assert.Len(t, value.([]any), 2)
Expand Down

0 comments on commit d93bf20

Please sign in to comment.