diff --git a/lib/debezium/converters/bit.go b/lib/debezium/converters/bit.go index 13fed317..1225c0cb 100644 --- a/lib/debezium/converters/bit.go +++ b/lib/debezium/converters/bit.go @@ -16,10 +16,18 @@ type BitConverter struct { charMaxLength int } -func (BitConverter) ToField(name string) debezium.Field { - return debezium.Field{ - FieldName: name, - Type: debezium.Boolean, +func (b BitConverter) ToField(name string) debezium.Field { + switch b.charMaxLength { + case 1: + return debezium.Field{ + FieldName: name, + Type: debezium.Boolean, + } + default: + return debezium.Field{ + FieldName: name, + Type: debezium.String, + } } } diff --git a/lib/debezium/converters/bit_test.go b/lib/debezium/converters/bit_test.go index 35db1495..40c99fad 100644 --- a/lib/debezium/converters/bit_test.go +++ b/lib/debezium/converters/bit_test.go @@ -5,6 +5,27 @@ import ( "testing" ) +func TestBitConverter_ToField(t *testing.T) { + { + // char size not specified + field := NewBitConverter(0).ToField("foo") + assert.Equal(t, "foo", field.FieldName) + assert.Equal(t, "string", string(field.Type)) + } + { + // char max size 1 + field := NewBitConverter(1).ToField("foo") + assert.Equal(t, "foo", field.FieldName) + assert.Equal(t, "boolean", string(field.Type)) + } + { + // char max size 5 + field := NewBitConverter(5).ToField("foo") + assert.Equal(t, "foo", field.FieldName) + assert.Equal(t, "string", string(field.Type)) + } +} + func TestBitConverter_Convert(t *testing.T) { { // char size not specified