diff --git a/sync_diff_inspector/report/report_test.go b/sync_diff_inspector/report/report_test.go index 6d36ffeb214..c5addaad7da 100644 --- a/sync_diff_inspector/report/report_test.go +++ b/sync_diff_inspector/report/report_test.go @@ -24,10 +24,10 @@ import ( "github.com/BurntSushi/toml" "github.com/DATA-DOG/go-sqlmock" "github.com/pingcap/tidb/pkg/parser" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" "github.com/pingcap/tiflow/sync_diff_inspector/chunk" "github.com/pingcap/tiflow/sync_diff_inspector/config" "github.com/pingcap/tiflow/sync_diff_inspector/source/common" + "github.com/pingcap/tiflow/sync_diff_inspector/utils" "github.com/stretchr/testify/require" ) @@ -45,10 +45,10 @@ func TestReport(t *testing.T) { report := NewReport(task) createTableSQL1 := "create table `test`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo1, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo1, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) createTableSQL2 := "create table `atest`.`atbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := utils.GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) tableDiffs := []*common.TableDiff{ @@ -162,7 +162,7 @@ func TestCalculateTotal(t *testing.T) { report := NewReport(task) createTableSQL := "create table `test`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) tableDiffs := []*common.TableDiff{ @@ -209,7 +209,7 @@ func TestCalculateTotal(t *testing.T) { func TestPrint(t *testing.T) { report := NewReport(task) createTableSQL := "create table `test`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) tableDiffs := []*common.TableDiff{ @@ -275,13 +275,13 @@ func TestPrint(t *testing.T) { func TestGetSnapshot(t *testing.T) { report := NewReport(task) createTableSQL1 := "create table `test`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo1, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo1, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) createTableSQL2 := "create table `atest`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := utils.GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) createTableSQL3 := "create table `xtest`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo3, err := dbutiltest.GetTableInfoBySQL(createTableSQL3, parser.New()) + tableInfo3, err := utils.GetTableInfoBySQL(createTableSQL3, parser.New()) require.NoError(t, err) tableDiffs := []*common.TableDiff{ @@ -392,16 +392,16 @@ func TestCommitSummary(t *testing.T) { outputDir := "./" report := NewReport(&config.TaskConfig{OutputDir: outputDir, FixDir: task.FixDir}) createTableSQL1 := "create table `test`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo1, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo1, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) createTableSQL2 := "create table `atest`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := utils.GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) createTableSQL3 := "create table `xtest`.`tbl`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo3, err := dbutiltest.GetTableInfoBySQL(createTableSQL3, parser.New()) + tableInfo3, err := utils.GetTableInfoBySQL(createTableSQL3, parser.New()) require.NoError(t, err) createTableSQL4 := "create table `xtest`.`tb1`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo4, err := dbutiltest.GetTableInfoBySQL(createTableSQL4, parser.New()) + tableInfo4, err := utils.GetTableInfoBySQL(createTableSQL4, parser.New()) require.NoError(t, err) tableDiffs := []*common.TableDiff{ { diff --git a/sync_diff_inspector/source/common/common_test.go b/sync_diff_inspector/source/common/common_test.go index 5649bbf347d..6c83caee099 100644 --- a/sync_diff_inspector/source/common/common_test.go +++ b/sync_diff_inspector/source/common/common_test.go @@ -19,14 +19,13 @@ import ( "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/util/dbutil" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" "github.com/pingcap/tiflow/sync_diff_inspector/utils" "github.com/stretchr/testify/require" ) func TestRowData(t *testing.T) { createTableSQL := "create table test.test(id int(24), name varchar(24), age int(24), primary key(id, name));" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) _, orderKeyCols := dbutil.SelectUniqueOrderKey(tableInfo) diff --git a/sync_diff_inspector/source/source_test.go b/sync_diff_inspector/source/source_test.go index bc69832547d..779a7f786c4 100644 --- a/sync_diff_inspector/source/source_test.go +++ b/sync_diff_inspector/source/source_test.go @@ -27,7 +27,6 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/util/dbutil" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" filter "github.com/pingcap/tidb/pkg/util/table-filter" router "github.com/pingcap/tidb/pkg/util/table-router" "github.com/pingcap/tiflow/sync_diff_inspector/chunk" @@ -293,7 +292,7 @@ func TestFallbackToRandomIfRangeIsSet(t *testing.T) { "`c` char(120) NOT NULL DEFAULT '', " + "PRIMARY KEY (`id`), KEY `k_1` (`k`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) table1 := &common.TableDiff{ @@ -625,7 +624,7 @@ func TestTiDBRouter(t *testing.T) { func prepareTiDBTables(t *testing.T, tableCases []*tableCaseType) []*common.TableDiff { tableDiffs := make([]*common.TableDiff, 0, len(tableCases)) for n, tableCase := range tableCases { - tableInfo, err := dbutiltest.GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) require.NoError(t, err) tableDiffs = append(tableDiffs, &common.TableDiff{ Schema: "source_test", diff --git a/sync_diff_inspector/splitter/index_fields_test.go b/sync_diff_inspector/splitter/index_fields_test.go index 788df79a116..c1c2a724f2b 100644 --- a/sync_diff_inspector/splitter/index_fields_test.go +++ b/sync_diff_inspector/splitter/index_fields_test.go @@ -17,7 +17,7 @@ import ( "testing" "github.com/pingcap/tidb/pkg/parser" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" + "github.com/pingcap/tiflow/sync_diff_inspector/utils" "github.com/stretchr/testify/require" ) @@ -30,7 +30,7 @@ func TestIndexFieldsSimple(t *testing.T) { "`c` char(120) NOT NULL DEFAULT '', " + "PRIMARY KEY (`id`), KEY `k_1` (`k`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) fields, err := indexFieldsFromConfigString("k", tableInfo) @@ -61,7 +61,7 @@ func TestIndexFieldsComposite(t *testing.T) { "KEY `k_1` (`k`)," + "UNIQUE INDEX `c_1` (`c`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) fields, err := indexFieldsFromConfigString("id, k", tableInfo) @@ -92,7 +92,7 @@ func TestIndexFieldsEmpty(t *testing.T) { "`c` char(120) NOT NULL DEFAULT '', " + "PRIMARY KEY (`id`), KEY `k_1` (`k`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) fields, err := indexFieldsFromConfigString("", tableInfo) diff --git a/sync_diff_inspector/splitter/splitter_test.go b/sync_diff_inspector/splitter/splitter_test.go index 1326f3c0f52..b301ba0e455 100644 --- a/sync_diff_inspector/splitter/splitter_test.go +++ b/sync_diff_inspector/splitter/splitter_test.go @@ -23,7 +23,6 @@ import ( sqlmock "github.com/DATA-DOG/go-sqlmock" "github.com/pingcap/tidb/pkg/parser" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" "github.com/pingcap/tiflow/sync_diff_inspector/chunk" "github.com/pingcap/tiflow/sync_diff_inspector/source/common" "github.com/pingcap/tiflow/sync_diff_inspector/utils" @@ -142,7 +141,7 @@ func TestSplitRangeByRandom(t *testing.T) { } for _, testCase := range testCases { - tableInfo, err := dbutiltest.GetTableInfoBySQL(testCase.createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(testCase.createTableSQL, parser.New()) require.NoError(t, err) splitCols, err := GetSplitFields(tableInfo, nil) @@ -322,7 +321,7 @@ func TestRandomSpliter(t *testing.T) { } for _, testCase := range testCases { - tableInfo, err := dbutiltest.GetTableInfoBySQL(testCase.createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(testCase.createTableSQL, parser.New()) require.NoError(t, err) info, needUnifiedTimeStamp := utils.ResetColumns(tableInfo, testCase.IgnoreColumns) @@ -357,7 +356,7 @@ func TestRandomSpliter(t *testing.T) { // Test Checkpoint stopJ := 3 - tableInfo, err := dbutiltest.GetTableInfoBySQL(testCases[0].createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(testCases[0].createTableSQL, parser.New()) require.NoError(t, err) tableDiff := &common.TableDiff{ @@ -431,7 +430,7 @@ func TestBucketSpliter(t *testing.T) { require.NoError(t, err) createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) testCases := []struct { @@ -743,7 +742,7 @@ func TestLimitSpliter(t *testing.T) { ctx := context.Background() createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) testCases := []struct { @@ -884,7 +883,7 @@ func TestChunkSize(t *testing.T) { require.NoError(t, err) createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) tableDiff := &common.TableDiff{ @@ -925,7 +924,7 @@ func TestChunkSize(t *testing.T) { require.Equal(t, randomIter.chunkSize, int64(100000)) createTableSQL = "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime)" - tableInfo, err = dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err = utils.GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) tableDiffNoIndex := &common.TableDiff{ diff --git a/sync_diff_inspector/utils/table.go b/sync_diff_inspector/utils/table.go index 4b602bb02fb..60dcd220a8b 100644 --- a/sync_diff_inspector/utils/table.go +++ b/sync_diff_inspector/utils/table.go @@ -32,7 +32,6 @@ import ( "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/collate" "github.com/pingcap/tidb/pkg/util/dbutil" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" "github.com/pingcap/tidb/pkg/util/mock" ) @@ -191,5 +190,44 @@ func GetTableInfo( if err != nil { return nil, errors.Trace(err) } - return dbutiltest.GetTableInfoBySQL(createTableSQL, parser2) + return GetTableInfoBySQL(createTableSQL, parser2) +} + +// GetTableInfoBySQL gets the table info from SQL. +func GetTableInfoBySQL(createTableSQL string, parser2 *parser.Parser) (table *model.TableInfo, err error) { + stmt, err := parser2.ParseOneStmt(createTableSQL, "", "") + if err != nil { + return nil, errors.Trace(err) + } + + s, ok := stmt.(*ast.CreateTableStmt) + if ok { + table, err := ddl.BuildTableInfoWithStmt(metabuild.NewContext(), s, mysql.DefaultCharset, "", nil) + if err != nil { + return nil, errors.Trace(err) + } + + // put primary key in indices + if table.PKIsHandle { + pkIndex := &model.IndexInfo{ + Name: pmodel.NewCIStr("PRIMARY"), + Primary: true, + State: model.StatePublic, + Unique: true, + Tp: pmodel.IndexTypeBtree, + Columns: []*model.IndexColumn{ + { + Name: table.GetPkName(), + Length: types.UnspecifiedLength, + }, + }, + } + + table.Indices = append(table.Indices, pkIndex) + } + + return table, nil + } + + return nil, errors.Errorf("get table info from sql %s failed", createTableSQL) } diff --git a/sync_diff_inspector/utils/utils_test.go b/sync_diff_inspector/utils/utils_test.go index be547e3f5f1..43f1cca7628 100644 --- a/sync_diff_inspector/utils/utils_test.go +++ b/sync_diff_inspector/utils/utils_test.go @@ -24,7 +24,6 @@ import ( "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/util/dbutil" - "github.com/pingcap/tidb/pkg/util/dbutil/dbutiltest" "github.com/pingcap/tiflow/sync_diff_inspector/chunk" "github.com/stretchr/testify/require" ) @@ -80,7 +79,7 @@ func TestStringsToInterface(t *testing.T) { func TestBasicTableUtilOperation(t *testing.T) { createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) query, orderKeyCols := GetTableRowsQueryFormat("test", "test", tableInfo, "123") @@ -242,7 +241,7 @@ func TestBasicTableUtilOperation(t *testing.T) { // Test ignore columns createTableSQL = "create table `test`.`test`(`a` int, `c` float, `b` varchar(10), `d` datetime, `e` timestamp, primary key(`a`, `b`), key(`c`, `d`))" - tableInfo, err = dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err = GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) require.Equal(t, len(tableInfo.Indices), 2) @@ -266,7 +265,7 @@ func TestGetCountAndMD5Checksum(t *testing.T) { defer conn.Close() createTableSQL := "create table `test`.`test`(`a` int, `c` float, `b` varchar(10), `d` datetime, primary key(`a`, `b`), key(`c`, `d`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) mock.ExpectQuery("SELECT COUNT.*FROM `test_schema`\\.`test_table` WHERE \\[23 45\\].*").WithArgs("123", "234").WillReturnRows(sqlmock.NewRows([]string{"CNT", "CHECKSUM"}).AddRow(123, 456)) @@ -286,7 +285,7 @@ func TestGetApproximateMid(t *testing.T) { defer conn.Close() createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), primary key(`a`, `b`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) rows := sqlmock.NewRows([]string{"a", "b"}).AddRow("5", "10") @@ -308,7 +307,7 @@ func TestGetApproximateMid(t *testing.T) { func TestGenerateSQLs(t *testing.T) { createTableSQL := "CREATE TABLE `diff_test`.`atest` (`id` int(24), `name` varchar(24), `birthday` datetime, `update_time` time, `money` decimal(20,2), `id_gen` int(11) GENERATED ALWAYS AS ((`id` + 1)) VIRTUAL, primary key(`id`, `name`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) rowsData := map[string]*dbutil.ColumnData{ @@ -327,7 +326,7 @@ func TestGenerateSQLs(t *testing.T) { // test the unique key createTableSQL2 := "CREATE TABLE `diff_test`.`atest` (`id` int(24), `name` varchar(24), `birthday` datetime, `update_time` time, `money` decimal(20,2), unique key(`id`, `name`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) replaceSQL = GenerateReplaceDML(rowsData, tableInfo2, "diff_test") deleteSQL = GenerateDeleteDML(rowsData, tableInfo2, "diff_test") @@ -357,7 +356,7 @@ func TestGenerateSQLs(t *testing.T) { func TestResetColumns(t *testing.T) { createTableSQL1 := "CREATE TABLE `test`.`atest` (`a` int, `b` int, `c` int, `d` int, primary key(`a`))" - tableInfo1, err := dbutiltest.GetTableInfoBySQL(createTableSQL1, parser.New()) + tableInfo1, err := GetTableInfoBySQL(createTableSQL1, parser.New()) require.NoError(t, err) tbInfo, hasTimeStampType := ResetColumns(tableInfo1, []string{"a"}) require.Equal(t, len(tbInfo.Columns), 3) @@ -366,14 +365,14 @@ func TestResetColumns(t *testing.T) { require.False(t, hasTimeStampType) createTableSQL2 := "CREATE TABLE `test`.`atest` (`a` int, `b` int, `c` int, `d` int, primary key(`a`), index idx(`b`, `c`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) tbInfo, _ = ResetColumns(tableInfo2, []string{"a", "b"}) require.Equal(t, len(tbInfo.Columns), 2) require.Equal(t, len(tbInfo.Indices), 0) createTableSQL3 := "CREATE TABLE `test`.`atest` (`a` int, `b` int, `c` int, `d` int, primary key(`a`), index idx(`b`, `c`))" - tableInfo3, err := dbutiltest.GetTableInfoBySQL(createTableSQL3, parser.New()) + tableInfo3, err := GetTableInfoBySQL(createTableSQL3, parser.New()) require.NoError(t, err) tbInfo, _ = ResetColumns(tableInfo3, []string{"b", "c"}) require.Equal(t, len(tbInfo.Columns), 2) @@ -454,7 +453,7 @@ func TestGetBetterIndex(t *testing.T) { }, } tableCase := tableCases[0] - tableInfo, err := dbutiltest.GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) require.NoError(t, err) indices := dbutil.FindAllIndex(tableInfo) for i, index := range indices { @@ -473,7 +472,7 @@ func TestGetBetterIndex(t *testing.T) { require.Equal(t, indices[0].Name.O, tableCase.selected) tableCase = tableCases[1] - tableInfo, err = dbutiltest.GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) + tableInfo, err = GetTableInfoBySQL(tableCase.createTableSQL, parser.New()) require.NoError(t, err) indices = dbutil.FindAllIndex(tableInfo) for i, index := range indices { @@ -521,7 +520,7 @@ func TestGetChunkIDFromSQLFileName(t *testing.T) { func TestCompareStruct(t *testing.T) { createTableSQL := "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) var isEqual bool @@ -532,7 +531,7 @@ func TestCompareStruct(t *testing.T) { // column length different createTableSQL2 := "create table `test`(`a` int, `b` varchar(10), `c` float, primary key(`a`, `b`), index(`c`))" - tableInfo2, err := dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err := GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -541,7 +540,7 @@ func TestCompareStruct(t *testing.T) { // column name differernt createTableSQL2 = "create table `test`(`aa` int, `b` varchar(10), `c` float, `d` datetime, primary key(`aa`, `b`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -550,7 +549,7 @@ func TestCompareStruct(t *testing.T) { // column type compatible createTableSQL2 = "create table `test`(`a` int, `b` char(10), `c` float, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -558,7 +557,7 @@ func TestCompareStruct(t *testing.T) { require.False(t, isPanic) createTableSQL2 = "create table `test`(`a` int(11), `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -567,7 +566,7 @@ func TestCompareStruct(t *testing.T) { // column type not compatible createTableSQL2 = "create table `test`(`a` int, `b` varchar(10), `c` int, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -576,7 +575,7 @@ func TestCompareStruct(t *testing.T) { // column properties not compatible createTableSQL2 = "create table `test`(`a` int, `b` varchar(11), `c` int, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -587,7 +586,7 @@ func TestCompareStruct(t *testing.T) { // index different createTableSQL2 = "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -598,11 +597,11 @@ func TestCompareStruct(t *testing.T) { // index column different createTableSQL = "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `b`), index(`c`))" - tableInfo, err = dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err = GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) createTableSQL2 = "create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`a`, `c`), index(`c`))" - tableInfo2, err = dbutiltest.GetTableInfoBySQL(createTableSQL2, parser.New()) + tableInfo2, err = GetTableInfoBySQL(createTableSQL2, parser.New()) require.NoError(t, err) isEqual, isPanic = CompareStruct([]*model.TableInfo{tableInfo, tableInfo2}, tableInfo) @@ -628,7 +627,7 @@ func TestGenerateSQLBlob(t *testing.T) { } for _, c := range cases { - tableInfo, err := dbutiltest.GetTableInfoBySQL(c.createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(c.createTableSQL, parser.New()) require.NoError(t, err) replaceSQL := GenerateReplaceDML(rowsData, tableInfo, "diff_test") @@ -640,7 +639,7 @@ func TestGenerateSQLBlob(t *testing.T) { func TestCompareBlob(t *testing.T) { createTableSQL := "create table `test`.`test`(`a` int primary key, `b` blob)" - tableInfo, err := dbutiltest.GetTableInfoBySQL(createTableSQL, parser.New()) + tableInfo, err := GetTableInfoBySQL(createTableSQL, parser.New()) require.NoError(t, err) _, orderKeyCols := GetTableRowsQueryFormat("test", "test", tableInfo, "123")