From 90f137df5de522585f590535557635ca067445cc Mon Sep 17 00:00:00 2001 From: lance6716 Date: Thu, 23 Dec 2021 11:45:47 +0800 Subject: [PATCH] This is an automated cherry-pick of #1103 Signed-off-by: ti-chi-bot --- reparo/syncer/util.go | 3 ++- reparo/syncer/util_test.go | 7 +++---- tests/dailytest/db.go | 10 ++++++++++ tests/reparo/binlog.go | 9 +++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/reparo/syncer/util.go b/reparo/syncer/util.go index 3b172c6f4..d08274ff5 100644 --- a/reparo/syncer/util.go +++ b/reparo/syncer/util.go @@ -46,7 +46,8 @@ func formatValue(value types.Datum, tp byte) types.Datum { case mysql.TypeSet: value = types.NewDatum(value.GetMysqlSet().Value) case mysql.TypeBit: - value = types.NewDatum(value.GetMysqlBit()) + // see drainer/translator/mysql.go formatData + value = types.NewDatum(value.GetUint64()) } return value diff --git a/reparo/syncer/util_test.go b/reparo/syncer/util_test.go index a84f2226c..7c593252f 100644 --- a/reparo/syncer/util_test.go +++ b/reparo/syncer/util_test.go @@ -15,8 +15,7 @@ var _ = check.Suite(&testUtilSuite{}) func (s *testUtilSuite) TestFormatValue(c *check.C) { datetime, err := time.Parse("20060102150405", "20190415121212") c.Assert(err, check.IsNil) - bitVal, err2 := types.NewBitLiteral("b'10010'") - c.Assert(err2, check.IsNil) + bitVal := uint64(12) testCases := []struct { value interface{} @@ -81,8 +80,8 @@ func (s *testUtilSuite) TestFormatValue(c *check.C) { { value: bitVal, tp: mysql.TypeBit, - expectStr: "0x12", - expectVal: types.BinaryLiteral([]byte{0x12}), + expectStr: "12", + expectVal: uint64(12), }, } diff --git a/tests/dailytest/db.go b/tests/dailytest/db.go index 27c908878..94e07cf9c 100644 --- a/tests/dailytest/db.go +++ b/tests/dailytest/db.go @@ -23,7 +23,12 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" +<<<<<<< HEAD "github.com/pingcap/parser/mysql" +======= + "github.com/pingcap/tidb/parser/mysql" + +>>>>>>> d8288e02 (reparo: fix can't decode bit type data (#1103)) "github.com/pingcap/tidb-binlog/tests/util" ) @@ -221,6 +226,11 @@ func genColumnData(table *table, column *column) (string, error) { isUnsigned := mysql.HasUnsignedFlag(tp.Flag) switch tp.Tp { + case mysql.TypeBit: + if randInt(0, 1) == 0 { + return "b'0'", nil + } + return "b'1'", nil case mysql.TypeTiny: var data int64 if isUnique { diff --git a/tests/reparo/binlog.go b/tests/reparo/binlog.go index 7df0bc5a0..3f6fb8878 100644 --- a/tests/reparo/binlog.go +++ b/tests/reparo/binlog.go @@ -20,6 +20,7 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/pingcap/tidb-binlog/tests/dailytest" "github.com/pingcap/tidb-binlog/tests/util" ) @@ -70,6 +71,14 @@ func main() { c varchar(10) NOT NULL, d time unique ); + `, + ` + create table ntest2( + a int, + b double NOT NULL DEFAULT 2.0, + c varchar(10) NOT NULL, + d bit(20) + ); `} dailytest.RunDailyTest(sourceDB, tableSQLs, cfg.WorkerCount, cfg.JobCount, cfg.Batch)