Skip to content

Commit

Permalink
reparo: fix can't decode bit type data (#1103) (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Feb 18, 2022
1 parent c032e8b commit 795af76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif

check-static: tools/bin/golangci-lint
$(GO) mod vendor
tools/bin/golangci-lint run $$($(PACKAGE_DIRECTORIES))
tools/bin/golangci-lint run --timeout 7m $$($(PACKAGE_DIRECTORIES))

clean:
go clean -i ./...
Expand Down
3 changes: 2 additions & 1 deletion reparo/syncer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions reparo/syncer/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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),
},
}

Expand Down
8 changes: 7 additions & 1 deletion tests/dailytest/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/tidb-binlog/tests/util"
"github.com/pingcap/tidb/parser/mysql"

"github.com/pingcap/tidb-binlog/tests/util"
)

func intRangeValue(column *column, min int64, max int64) (int64, int64) {
Expand Down Expand Up @@ -221,6 +222,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 {
Expand Down
9 changes: 9 additions & 0 deletions tests/reparo/binlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 795af76

Please sign in to comment.