Skip to content

Commit

Permalink
sink: fix float support in Avro (#1447) #1450
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Feb 24, 2021
1 parent 6eb2159 commit 52a6d9e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cdc/sink/codec/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ func columnToAvroNativeData(col *model.Column) (interface{}, string, error) {
return handleUnsignedInt64()
}
return col.Value.(int64), "long", nil
case mysql.TypeFloat:
return col.Value.(float64), "float", nil
default:
avroType, err := getAvroDataTypeFallback(col.Value)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cdc/sink/codec/avro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *avroBatchEncoderSuite) TestAvroEncodeOnly(c *check.C) {
{Name: "id", Value: int64(1), Type: mysql.TypeLong},
{Name: "myint", Value: int64(2), Type: mysql.TypeLong},
{Name: "mybool", Value: int64(1), Type: mysql.TypeTiny},
{Name: "myfloat", Value: float32(3.14), Type: mysql.TypeFloat},
{Name: "myfloat", Value: float64(3.14), Type: mysql.TypeFloat},
{Name: "mybytes", Value: []byte("Hello World"), Type: mysql.TypeBlob},
{Name: "ts", Value: time.Now().Format(types.TimeFSPFormat), Type: mysql.TypeTimestamp},
})
Expand Down
4 changes: 4 additions & 0 deletions integration/tests/case_many_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (s *ManyTypesCase) Run(ctx *framework.TaskContext) error {
t_boolean BOOLEAN,
t_bigint BIGINT,
t_double DOUBLE,
t_float FLOAT,
t_decimal DECIMAL(38, 19),
t_bit BIT(64),
t_date DATE,
Expand All @@ -73,6 +74,7 @@ func (s *ManyTypesCase) Run(ctx *framework.TaskContext) error {
t_boolean BOOLEAN,
t_bigint BIGINT,
t_double DOUBLE,
t_float FLOAT,
t_decimal DECIMAL(38, 19),
t_date DATE,
t_datetime DATETIME,
Expand All @@ -93,6 +95,7 @@ func (s *ManyTypesCase) Run(ctx *framework.TaskContext) error {
t_boolean BOOLEAN,
t_bigint BIGINT,
t_double DOUBLE,
t_float FLOAT,
t_decimal DECIMAL(38, 19),
t_bit BIT(64),
t_date DATE,
Expand Down Expand Up @@ -136,6 +139,7 @@ func (s *ManyTypesCase) Run(ctx *framework.TaskContext) error {
"t_boolean": true,
"t_bigint": math.MaxInt64,
"t_double": 1.01234,
"t_float": 2.45678,
"t_decimal": "12345.6789",
"t_date": time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
"t_datetime": time.Now(),
Expand Down

0 comments on commit 52a6d9e

Please sign in to comment.