From b50b23d6e253af2c2aca3f571b05f7fb53696cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 26 Nov 2021 17:44:37 +0100 Subject: [PATCH 1/2] Fix handling of JSON columns --- cdc/sink/codec/avro.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cdc/sink/codec/avro.go b/cdc/sink/codec/avro.go index 1d6452975ff..7a7b2b3feef 100644 --- a/cdc/sink/codec/avro.go +++ b/cdc/sink/codec/avro.go @@ -30,7 +30,6 @@ import ( "github.com/pingcap/ticdc/cdc/model" cerror "github.com/pingcap/ticdc/pkg/errors" "github.com/pingcap/tidb/types" - tijson "github.com/pingcap/tidb/types/json" "go.uber.org/zap" ) @@ -474,7 +473,7 @@ func columnToAvroNativeData(col *model.Column, tz *time.Location) (interface{}, case mysql.TypeYear: return col.Value.(int64), "long", nil case mysql.TypeJSON: - return col.Value.(tijson.BinaryJSON).String(), "string", nil + return col.Value.(string), "string", nil case mysql.TypeNewDecimal: return col.Value.(string), "string", nil case mysql.TypeEnum: From e189e50904d10de67ff96afc8c7c8d0cf9082aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 26 Nov 2021 18:03:07 +0100 Subject: [PATCH 2/2] Avro: Add test for JSON --- cdc/sink/codec/avro_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cdc/sink/codec/avro_test.go b/cdc/sink/codec/avro_test.go index 97074664fa8..779be79c451 100644 --- a/cdc/sink/codec/avro_test.go +++ b/cdc/sink/codec/avro_test.go @@ -88,6 +88,7 @@ func (s *avroBatchEncoderSuite) TestAvroEncodeOnly(c *check.C) { {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}, + {Name: "myjson", Value: "{\"foo\": \"bar\"}", Type: mysql.TypeJSON}, }, time.Local) c.Assert(err, check.IsNil)