Skip to content

Commit

Permalink
*: update tidb (#618)
Browse files Browse the repository at this point in the history
close #617
  • Loading branch information
Ehco1996 authored May 16, 2022
1 parent b870b1b commit b3ea358
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 342 deletions.
12 changes: 6 additions & 6 deletions go.mod1
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/pingcap/check v0.0.0-20211026125417-57bd13f7b5f0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20220303073211-00fea37feb66
github.com/pingcap/kvproto v0.0.0-20220314103629-10e688307221
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee
github.com/pingcap/tidb v1.1.0-beta.0.20220321041832-f9beb51a644c
github.com/pingcap/tidb/parser v0.0.0-20220321041832-f9beb51a644c
github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3
github.com/pingcap/kvproto v0.0.0-20220328072018-6e75c12dbd73
github.com/pingcap/log v1.1.0
github.com/pingcap/tidb v1.1.0-beta.0.20220511160835-98c31070d958
github.com/pingcap/tidb/parser v0.0.0-20220511160835-98c31070d958
github.com/pingcap/tiflow v0.0.0-20220217071740-1e3dd1550494
github.com/pingcap/tipb v0.0.0-20220215045658-d12dec7a7609
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.2-0.20220504104629-106ec21d14df
github.com/tikv/pd/client v0.0.0-20220307081149-841fa61e9710
go.etcd.io/etcd/api/v3 v3.5.2
go.etcd.io/etcd/client/v3 v3.5.2
Expand Down
52 changes: 32 additions & 20 deletions go.sum1

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/check/table_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ func (c *ShardingTablesChecker) findAutoIncrementKey(stmt *ast.CreateTableStmt,

if hasAutoIncrementOpt {
if isUnique {
autoIncrementKeys[col.Name.Name.O] = col.Tp.Tp == mysql.TypeLonglong
autoIncrementKeys[col.Name.Name.O] = col.Tp.GetType() == mysql.TypeLonglong
} else {
autoIncrementCols[col.Name.Name.O] = col.Tp.Tp == mysql.TypeLonglong
autoIncrementCols[col.Name.Name.O] = col.Tp.GetType() == mysql.TypeLonglong
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ func AnalyzeValuesFromBuckets(valueString string, cols []*model.ColumnInfo) ([]s
}

for i, col := range cols {
if IsTimeTypeAndNeedDecode(col.Tp) {
if IsTimeTypeAndNeedDecode(col.GetType()) {
// check if values[i] is already a time string
sc := &stmtctx.StatementContext{TimeZone: time.UTC}
_, err := types.ParseTime(sc, values[i], col.Tp, types.MinFsp)
_, err := types.ParseTime(sc, values[i], col.GetType(), types.MinFsp)
if err == nil {
continue
}
Expand Down
16 changes: 10 additions & 6 deletions pkg/dbutil/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,39 +185,43 @@ func (s *testDBSuite) TestGetParser(c *C) {
}

func (s *testDBSuite) TestAnalyzeValuesFromBuckets(c *C) {
ftTypeDatetime := types.NewFieldType(pmysql.TypeDatetime)
ftTypeTimestamp := types.NewFieldType(pmysql.TypeTimestamp)
ftTypeDate := types.NewFieldType(pmysql.TypeDate)

cases := []struct {
value string
col *model.ColumnInfo
expect string
}{
{
"2021-03-05 21:31:03",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeDatetime}},
&model.ColumnInfo{FieldType: *ftTypeDatetime},
"2021-03-05 21:31:03",
},
{
"2021-03-05 21:31:03",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeTimestamp}},
&model.ColumnInfo{FieldType: *ftTypeTimestamp},
"2021-03-05 21:31:03",
},
{
"2021-03-05",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeDate}},
&model.ColumnInfo{FieldType: *ftTypeDate},
"2021-03-05",
},
{
"1847956477067657216",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeDatetime}},
&model.ColumnInfo{FieldType: *ftTypeDatetime},
"2020-01-01 10:00:00",
},
{
"1847955927311843328",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeTimestamp}},
&model.ColumnInfo{FieldType: *ftTypeTimestamp},
"2020-01-01 02:00:00",
},
{
"1847955789872889856",
&model.ColumnInfo{FieldType: types.FieldType{Tp: pmysql.TypeDate}},
&model.ColumnInfo{FieldType: *ftTypeDate},
"2020-01-01 00:00:00",
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbutil/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func EqualTableInfo(tableInfo1, tableInfo2 *model.TableInfo) (bool, string) {
if col.Name.O != tableInfo2.Columns[j].Name.O {
return false, fmt.Sprintf("column name not equal, one is %s another is %s", col.Name.O, tableInfo2.Columns[j].Name.O)
}
if col.Tp != tableInfo2.Columns[j].Tp {
return false, fmt.Sprintf("column %s's type not equal, one is %v another is %v", col.Name.O, col.Tp, tableInfo2.Columns[j].Tp)
if col.GetType() != tableInfo2.Columns[j].GetType() {
return false, fmt.Sprintf("column %s's type not equal, one is %v another is %v", col.Name.O, col.GetType(), tableInfo2.Columns[j].GetType())
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/diff/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getColumnsFromIndex(index *model.IndexInfo, tableInfo *model.TableInfo) []*
}

func needQuotes(ft types.FieldType) bool {
return !(dbutil.IsNumberType(ft.Tp) || dbutil.IsFloatType(ft.Tp))
return !(dbutil.IsNumberType(ft.GetType()) || dbutil.IsFloatType(ft.GetType()))
}

func rowContainsCols(row map[string]*dbutil.ColumnData, cols []*model.ColumnInfo) bool {
Expand Down
8 changes: 4 additions & 4 deletions pkg/importer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func genRowData(table *table) (string, error) {
func genColumnData(table *table, column *column) (string, error) {
tp := column.tp
_, isUnique := table.uniqIndices[column.name]
isUnsigned := mysql.HasUnsignedFlag(tp.Flag)
isUnsigned := mysql.HasUnsignedFlag(tp.GetFlag())

switch tp.Tp {
switch tp.GetType() {
case mysql.TypeTiny:
var data int64
if isUnique {
Expand Down Expand Up @@ -149,9 +149,9 @@ func genColumnData(table *table, column *column) (string, error) {
case mysql.TypeVarchar, mysql.TypeString, mysql.TypeTinyBlob, mysql.TypeBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob:
data := []byte{'\''}
if isUnique {
data = append(data, []byte(column.data.uniqString(tp.Flen))...)
data = append(data, []byte(column.data.uniqString(tp.GetFlen()))...)
} else {
data = append(data, []byte(randString(randInt(1, tp.Flen)))...)
data = append(data, []byte(randString(randInt(1, tp.GetFlen())))...)
}

data = append(data, '\'')
Expand Down
6 changes: 3 additions & 3 deletions pkg/schemacmp/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func restoreColumnInfoFromUnwrapped(ctx *format.RestoreCtx, col []interface{}, c
if col[columnInfoTupleIndexGeneratedStored].(bool) {
ctx.WriteKeyWord(" STORED")
}
if mysql.HasNotNullFlag(typ.Flag) {
if mysql.HasNotNullFlag(typ.GetFlag()) {
ctx.WriteKeyWord(" NOT NULL")
}
if defVal := col[columnInfoTupleIndexDefaultValue]; defVal != nil {
ctx.WriteKeyWord(" DEFAULT ")
ctx.WritePlainf("%v", defVal)
}
if mysql.HasAutoIncrementFlag(typ.Flag) {
if mysql.HasAutoIncrementFlag(typ.GetFlag()) {
ctx.WriteKeyWord(" AUTO_INCREMENT")
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func encodeTableInfoToLattice(ti *model.TableInfo) Tuple {
columns := make(columnMap)
for _, ci := range ti.Columns {
columns[ci.Name.L] = encodeColumnInfoToLattice(ci)
if !hasExplicitPrimaryKey && (ci.Flag&mysql.PriKeyFlag) != 0 {
if !hasExplicitPrimaryKey && (ci.GetFlag()&mysql.PriKeyFlag) != 0 {
indices["primary"] = encodeImplicitPrimaryKeyToLattice(ci)
}
}
Expand Down
46 changes: 22 additions & 24 deletions pkg/schemacmp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,35 @@ func decodeAntiKeys(encoded byte) uint {
// encodeTypeTpAsLattice
func encodeFieldTypeToLattice(ft *types.FieldType) Tuple {
var flen, dec Lattice
if ft.Tp == mysql.TypeNewDecimal {
flen = Singleton(ft.Flen)
dec = Singleton(ft.Decimal)
if ft.GetType() == mysql.TypeNewDecimal {
flen = Singleton(ft.GetFlen())
dec = Singleton(ft.GetDecimal())
} else {
flen = Int(ft.Flen)
dec = Int(ft.Decimal)
flen = Int(ft.GetFlen())
dec = Int(ft.GetDecimal())
}

var defVal Lattice
if mysql.HasAutoIncrementFlag(ft.Flag) || !mysql.HasNoDefaultValueFlag(ft.Flag) {
defVal = Maybe(Singleton(ft.Flag & flagMaskDefVal))
if mysql.HasAutoIncrementFlag(ft.GetFlag()) || !mysql.HasNoDefaultValueFlag(ft.GetFlag()) {
defVal = Maybe(Singleton(ft.GetFlag() & flagMaskDefVal))
} else {
defVal = Maybe(nil)
}

return Tuple{
FieldTp(ft.Tp),
FieldTp(ft.GetType()),
flen,
dec,

// TODO: recognize if the remaining flags can be merged or not.
Singleton(ft.Flag &^ (flagMaskDefVal | mysql.NotNullFlag | flagMaskKeys)),
Bool(!mysql.HasNotNullFlag(ft.Flag)),
Byte(encodeAntiKeys(ft.Flag)),
Singleton(ft.GetFlag() &^ (flagMaskDefVal | mysql.NotNullFlag | flagMaskKeys)),
Bool(!mysql.HasNotNullFlag(ft.GetFlag())),
Byte(encodeAntiKeys(ft.GetFlag())),
defVal,

Singleton(ft.Charset),
Singleton(ft.Collate),
StringList(ft.Elems),
Singleton(ft.GetCharset()),
Singleton(ft.GetCollate()),
StringList(ft.GetElems()),
}
}

Expand All @@ -104,16 +104,14 @@ func decodeFieldTypeFromLattice(tup Tuple) *types.FieldType {
} else {
flags |= mysql.NoDefaultValueFlag
}

return &types.FieldType{
Tp: lst[fieldTypeTupleIndexTp].(byte),
Flen: lst[fieldTypeTupleIndexFlen].(int),
Decimal: lst[fieldTypeTupleIndexDec].(int),
Flag: flags,
Charset: lst[fieldTypeTupleIndexCharset].(string),
Collate: lst[fieldTypeTupleIndexCollate].(string),
Elems: lst[fieldTypeTupleIndexElems].([]string),
}
ft := types.NewFieldType(lst[fieldTypeTupleIndexTp].(byte))
ft.SetFlag(flags)
ft.SetFlen(lst[fieldTypeTupleIndexFlen].(int))
ft.SetDecimal(lst[fieldTypeTupleIndexDec].(int))
ft.SetCharset(lst[fieldTypeTupleIndexCharset].(string))
ft.SetCollate(lst[fieldTypeTupleIndexCollate].(string))
ft.SetElems(lst[fieldTypeTupleIndexElems].([]string))
return ft
}

type typ struct{ Tuple }
Expand Down
Loading

0 comments on commit b3ea358

Please sign in to comment.