Skip to content

Commit

Permalink
Fix panic on unsigned tinyint (#2649) (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed Aug 29, 2021
1 parent ab1b693 commit b9e5a1f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cdc/sink/codec/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ func columnToAvroNativeData(col *model.Column, tz *time.Location) (interface{},
case mysql.TypeBit:
return handleUnsignedInt64()
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24:
if col.Flag.IsUnsigned() {
return int32(col.Value.(uint64)), "int", nil
}
return int32(col.Value.(int64)), "int", nil
case mysql.TypeLong:
if col.Flag.IsUnsigned() {
Expand Down
1 change: 1 addition & 0 deletions cdc/sink/codec/avro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (s *avroBatchEncoderSuite) TestAvroEncode(c *check.C) {
{Name: "id", Type: mysql.TypeLong, Flag: model.HandleKeyFlag, Value: int64(1)},
{Name: "name", Type: mysql.TypeVarchar, Value: "Bob"},
{Name: "tiny", Type: mysql.TypeTiny, Value: int64(255)},
{Name: "utiny", Type: mysql.TypeTiny, Flag: model.UnsignedFlag, Value: uint64(100)},
{Name: "comment", Type: mysql.TypeBlob, Value: []byte("测试")},
},
}
Expand Down

0 comments on commit b9e5a1f

Please sign in to comment.