Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 19, 2024
1 parent 6191a96 commit 1f5c82b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion sources/mysql/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ func (m MySQLAdapter) PartitionKeys() []string {

func valueConverterForType(d schema.DataType, opts *schema.Opts) (converters.ValueConverter, error) {
switch d {
case schema.Bit, schema.Boolean:
case schema.Bit:
if opts == nil || opts.Size == nil {
return nil, fmt.Errorf("size is required for bit type")
}

if *opts.Size == 1 {
return converters.BooleanPassthrough{}, nil
}

return converters.BytesPassthrough{}, nil
case schema.Boolean:
return converters.BooleanPassthrough{}, nil
case schema.TinyInt, schema.SmallInt:
return converters.Int16Passthrough{}, nil
Expand Down
16 changes: 15 additions & 1 deletion sources/mysql/adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,27 @@ func TestValueConverterForType(t *testing.T) {
expectedErr: "unable get value converter for DataType(-1)",
},
{
name: "bit",
name: "bit(1)",
dataType: schema.Bit,
opts: &schema.Opts{
Size: typing.ToPtr(1),
},
expected: debezium.Field{
Type: "boolean",
FieldName: colName,
},
},
{
name: "bit(5)",
dataType: schema.Bit,
opts: &schema.Opts{
Size: typing.ToPtr(5),
},
expected: debezium.Field{
Type: debezium.Bytes,
FieldName: colName,
},
},
{
name: "tinyint",
dataType: schema.TinyInt,
Expand Down

0 comments on commit 1f5c82b

Please sign in to comment.