From d93bf20e330fbb61db8fe5e68425f9285ce8d82c Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 11 Dec 2024 21:59:44 -0800 Subject: [PATCH] [Debezium] ItemsMetadata is optional (#1076) --- lib/debezium/schema.go | 9 +++++++-- lib/debezium/types_test.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/debezium/schema.go b/lib/debezium/schema.go index 365750020..a36a5e6d8 100644 --- a/lib/debezium/schema.go +++ b/lib/debezium/schema.go @@ -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) { @@ -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 } diff --git a/lib/debezium/types_test.go b/lib/debezium/types_test.go index 8196057fd..3adc9a17a 100644 --- a/lib/debezium/types_test.go +++ b/lib/debezium/types_test.go @@ -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)