From bb61a2b749e37fbe2a222fa649b0230eb2273f84 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 11 Dec 2024 21:48:16 -0800 Subject: [PATCH 1/3] Use ptr. --- lib/debezium/schema.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/debezium/schema.go b/lib/debezium/schema.go index 36575002..58348285 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"` } 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 } From 44501aa802cd591c091f58c562a0162514b8e901 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 11 Dec 2024 21:48:55 -0800 Subject: [PATCH 2/3] omitempty. --- lib/debezium/schema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debezium/schema.go b/lib/debezium/schema.go index 58348285..a36a5e6d 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) { From 4b696f82cfaf7c6634a10ad18948d46365ad3b31 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 11 Dec 2024 21:54:18 -0800 Subject: [PATCH 3/3] Clean up. --- lib/debezium/types_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debezium/types_test.go b/lib/debezium/types_test.go index 8196057f..3adc9a17 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)