diff --git a/cdc/sink/codec/canal/canal_json_decoder_test.go b/cdc/sink/codec/canal/canal_json_decoder_test.go index 2ce4f66b31a..d744eee184a 100644 --- a/cdc/sink/codec/canal/canal_json_decoder_test.go +++ b/cdc/sink/codec/canal/canal_json_decoder_test.go @@ -36,7 +36,8 @@ func TestNewCanalJSONBatchDecoder4RowMessage(t *testing.T) { }) require.NotNil(t, encoder) - err := encoder.AppendRowChangedEvent(context.Background(), "", testCaseInsert, nil) + insertEvent, _, _ := newLargeEvent4Test(t) + err := encoder.AppendRowChangedEvent(context.Background(), "", insertEvent, nil) require.Nil(t, err) messages := encoder.Build() @@ -59,9 +60,9 @@ func TestNewCanalJSONBatchDecoder4RowMessage(t *testing.T) { consumed, err := decoder.NextRowChangedEvent() require.Nil(t, err) - require.Equal(t, testCaseInsert.Table, consumed.Table) + require.Equal(t, insertEvent.Table, consumed.Table) if encodeEnable && decodeEnable { - require.Equal(t, testCaseInsert.CommitTs, consumed.CommitTs) + require.Equal(t, insertEvent.CommitTs, consumed.CommitTs) } else { require.Equal(t, uint64(0), consumed.CommitTs) } @@ -71,7 +72,7 @@ func TestNewCanalJSONBatchDecoder4RowMessage(t *testing.T) { require.True(t, ok) require.Equal(t, expected, col.Value) - for _, item := range testCaseInsert.Columns { + for _, item := range insertEvent.Columns { if item.Name == col.Name { require.Equal(t, item.Type, col.Type) } diff --git a/cdc/sink/codec/canal/canal_json_encoder_test.go b/cdc/sink/codec/canal/canal_json_encoder_test.go index 02eeacec50c..6d84189540c 100644 --- a/cdc/sink/codec/canal/canal_json_encoder_test.go +++ b/cdc/sink/codec/canal/canal_json_encoder_test.go @@ -52,7 +52,8 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { encoder, ok := builder.Build().(*JSONBatchEncoder) require.True(t, ok) - data, err := newJSONMessageForDML(testCaseInsert, encoder.config, encoder.builder, false) + insertEvent, updateEvent, deleteEvent := newLargeEvent4Test(t) + data, err := newJSONMessageForDML(insertEvent, encoder.config, encoder.builder, false) require.Nil(t, err) var msg canalJSONMessageInterface = &JSONMessage{} err = json.Unmarshal(data, msg) @@ -62,12 +63,12 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.NotNil(t, jsonMsg.Data) require.Nil(t, jsonMsg.Old) require.Equal(t, "INSERT", jsonMsg.EventType) - require.Equal(t, convertToCanalTs(testCaseInsert.CommitTs), jsonMsg.ExecutionTime) + require.Equal(t, convertToCanalTs(insertEvent.CommitTs), jsonMsg.ExecutionTime) require.Equal(t, "cdc", jsonMsg.Schema) require.Equal(t, "person", jsonMsg.Table) require.False(t, jsonMsg.IsDDL) - for _, col := range testCaseInsert.Columns { + for _, col := range insertEvent.Columns { require.Contains(t, jsonMsg.Data[0], col.Name) require.Contains(t, jsonMsg.SQLType, col.Name) require.Contains(t, jsonMsg.MySQLType, col.Name) @@ -101,7 +102,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.Equal(t, item.expectedEncodedValue, obtainedValue) } - data, err = newJSONMessageForDML(testCaseUpdate, encoder.config, encoder.builder, false) + data, err = newJSONMessageForDML(updateEvent, encoder.config, encoder.builder, false) require.NoError(t, err) jsonMsg = &JSONMessage{} err = json.Unmarshal(data, jsonMsg) @@ -110,16 +111,16 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.NotNil(t, jsonMsg.Old) require.Equal(t, "UPDATE", jsonMsg.EventType) - for _, col := range testCaseUpdate.Columns { + for _, col := range updateEvent.Columns { require.Contains(t, jsonMsg.Data[0], col.Name) require.Contains(t, jsonMsg.SQLType, col.Name) require.Contains(t, jsonMsg.MySQLType, col.Name) } - for _, col := range testCaseUpdate.PreColumns { + for _, col := range updateEvent.PreColumns { require.Contains(t, jsonMsg.Old[0], col.Name) } - data, err = newJSONMessageForDML(testCaseDelete, encoder.config, encoder.builder, false) + data, err = newJSONMessageForDML(deleteEvent, encoder.config, encoder.builder, false) require.Nil(t, err) jsonMsg = &JSONMessage{} err = json.Unmarshal(data, jsonMsg) @@ -128,11 +129,11 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.Nil(t, jsonMsg.Old) require.Equal(t, "DELETE", jsonMsg.EventType) - for _, col := range testCaseDelete.PreColumns { + for _, col := range deleteEvent.PreColumns { require.Contains(t, jsonMsg.Data[0], col.Name) } - data, err = newJSONMessageForDML(testCaseDelete, encoder.config, encoder.builder, false) + data, err = newJSONMessageForDML(deleteEvent, encoder.config, encoder.builder, false) require.NoError(t, err) jsonMsg = &JSONMessage{} err = json.Unmarshal(data, jsonMsg) @@ -140,7 +141,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.NotNil(t, jsonMsg.Data) require.Nil(t, jsonMsg.Old) - for _, col := range testCaseDelete.PreColumns { + for _, col := range deleteEvent.PreColumns { require.Contains(t, jsonMsg.Data[0], col.Name) require.Contains(t, jsonMsg.SQLType, col.Name) require.Contains(t, jsonMsg.MySQLType, col.Name) @@ -148,7 +149,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { encoder, ok = newJSONBatchEncoder(&common.Config{DeleteOnlyHandleKeyColumns: true}).(*JSONBatchEncoder) require.True(t, ok) - data, err = newJSONMessageForDML(testCaseDelete, encoder.config, encoder.builder, false) + data, err = newJSONMessageForDML(deleteEvent, encoder.config, encoder.builder, false) require.NoError(t, err) jsonMsg = &JSONMessage{} err = json.Unmarshal(data, jsonMsg) @@ -156,7 +157,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.NotNil(t, jsonMsg.Data) require.Nil(t, jsonMsg.Old) - for _, col := range testCaseDelete.PreColumns { + for _, col := range deleteEvent.PreColumns { if col.Flag.IsHandleKey() { require.Contains(t, jsonMsg.Data[0], col.Name) require.Contains(t, jsonMsg.SQLType, col.Name) @@ -176,7 +177,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { encoder, ok = NewJSONBatchEncoderBuilder(codecConfig).Build().(*JSONBatchEncoder) require.True(t, ok) - data, err = newJSONMessageForDML(testCaseUpdate, encoder.config, encoder.builder, false) + data, err = newJSONMessageForDML(updateEvent, encoder.config, encoder.builder, false) require.Nil(t, err) withExtension := &canalJSONMessageWithTiDBExtension{} @@ -184,7 +185,7 @@ func TestNewCanalJSONMessage4DML(t *testing.T) { require.Nil(t, err) require.NotNil(t, withExtension.Extensions) - require.Equal(t, testCaseUpdate.CommitTs, withExtension.Extensions.CommitTs) + require.Equal(t, updateEvent.CommitTs, withExtension.Extensions.CommitTs) } func TestNewCanalJSONMessageHandleKeyOnly4LargeMessage(t *testing.T) { @@ -196,7 +197,8 @@ func TestNewCanalJSONMessageHandleKeyOnly4LargeMessage(t *testing.T) { codecConfig.MaxMessageBytes = 500 encoder := newJSONBatchEncoder(codecConfig) - err := encoder.AppendRowChangedEvent(context.Background(), "", testCaseInsert, func() {}) + insertEvent, _, _ := newLargeEvent4Test(t) + err := encoder.AppendRowChangedEvent(context.Background(), "", insertEvent, func() {}) require.NoError(t, err) message := encoder.Build()[0] @@ -206,7 +208,7 @@ func TestNewCanalJSONMessageHandleKeyOnly4LargeMessage(t *testing.T) { require.NoError(t, err) require.True(t, decoded.Extensions.OnlyHandleKey) - for _, col := range testCaseInsert.Columns { + for _, col := range insertEvent.Columns { if col.Flag.IsHandleKey() { require.Contains(t, decoded.Data[0], col.Name) require.Contains(t, decoded.SQLType, col.Name) @@ -261,7 +263,8 @@ func TestBatching(t *testing.T) { }) require.NotNil(t, encoder) - updateCase := *testCaseUpdate + _, updateEvent, _ := newLargeEvent4Test(t) + updateCase := *updateEvent for i := 1; i <= 1000; i++ { ts := uint64(i) updateCase.CommitTs = ts @@ -553,7 +556,8 @@ func TestCanalJSONContentCompatibleE2E(t *testing.T) { builder := NewJSONBatchEncoderBuilder(codecConfig) encoder := builder.Build() - err := encoder.AppendRowChangedEvent(ctx, "", testCaseInsert, func() {}) + insertEvent, _, _ := newLargeEvent4Test(t) + err := encoder.AppendRowChangedEvent(ctx, "", insertEvent, func() {}) require.NoError(t, err) message := encoder.Build()[0] @@ -571,9 +575,9 @@ func TestCanalJSONContentCompatibleE2E(t *testing.T) { decodedEvent, err := decoder.NextRowChangedEvent() require.NoError(t, err) - require.Equal(t, decodedEvent.CommitTs, testCaseInsert.CommitTs) - require.Equal(t, decodedEvent.Table.Schema, testCaseInsert.Table.Schema) - require.Equal(t, decodedEvent.Table.Table, testCaseInsert.Table.Table) + require.Equal(t, decodedEvent.CommitTs, insertEvent.CommitTs) + require.Equal(t, decodedEvent.Table.Schema, insertEvent.Table.Schema) + require.Equal(t, decodedEvent.Table.Table, insertEvent.Table.Table) obtainedColumns := make(map[string]*model.Column, len(decodedEvent.Columns)) for _, column := range decodedEvent.Columns { @@ -581,7 +585,7 @@ func TestCanalJSONContentCompatibleE2E(t *testing.T) { } expectedValue := collectExpectedDecodedValue(testColumnsTable) - for _, actual := range testCaseInsert.Columns { + for _, actual := range insertEvent.Columns { obtained, ok := obtainedColumns[actual.Name] require.True(t, ok) require.Equal(t, actual.Type, obtained.Type) diff --git a/cdc/sink/codec/canal/type_test.go b/cdc/sink/codec/canal/type_test.go index 6f9b81b8e06..aacb5f73c00 100644 --- a/cdc/sink/codec/canal/type_test.go +++ b/cdc/sink/codec/canal/type_test.go @@ -18,6 +18,7 @@ import ( "github.com/pingcap/tiflow/cdc/entry" "github.com/pingcap/tiflow/cdc/model" + "github.com/pingcap/tiflow/cdc/sink/codec/common" "github.com/pingcap/tiflow/cdc/sink/codec/internal" "github.com/stretchr/testify/require" ) @@ -40,10 +41,10 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[0].ID) require.True(t, ok) - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "int", mysqlType) // mysql type with the default type length - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "int(11)", mysqlType) flag := tableInfo.ColumnsFlag[colInfos[0].ID] @@ -53,9 +54,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(4)", mysqlType) flag = tableInfo.ColumnsFlag[colInfos[1].ID] @@ -65,9 +66,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "smallint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "smallint(6)", mysqlType) flag = tableInfo.ColumnsFlag[colInfos[2].ID] @@ -78,9 +79,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[3].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumint(9)", mysqlType) javaType, err = getJavaSQLType(int64(8388607), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -89,9 +90,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[4].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bigint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bigint(20)", mysqlType) javaType, err = getJavaSQLType(int64(9223372036854775807), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -111,10 +112,10 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[0].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "int unsigned", mysqlType) // mysql type with the default type length - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "int(10) unsigned", mysqlType) javaType, err = getJavaSQLType(uint64(2147483647), columnInfo.FieldType.GetType(), flag) @@ -133,9 +134,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(3) unsigned", mysqlType) javaType, err = getJavaSQLType(uint64(127), columnInfo.FieldType.GetType(), flag) @@ -154,9 +155,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "smallint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "smallint(5) unsigned", mysqlType) javaType, err = getJavaSQLType(uint64(32767), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -174,9 +175,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[3].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumint(8) unsigned", mysqlType) javaType, err = getJavaSQLType(uint64(8388607), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -194,9 +195,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[4].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bigint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bigint(20) unsigned", mysqlType) javaType, err = getJavaSQLType(uint64(9223372036854775807), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -224,37 +225,37 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "int", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "int(10)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(3)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "smallint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "smallint(5)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumint(8)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bigint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bigint(19)", mysqlType) sql = `create table test.t4 ( @@ -270,37 +271,37 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "int unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "int(10) unsigned", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(3) unsigned", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "smallint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "smallint(5) unsigned", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumint(8) unsigned", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bigint unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bigint(19) unsigned", mysqlType) sql = `create table test.t5 ( @@ -316,37 +317,37 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "int unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "int(10) unsigned zerofill", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(3) unsigned zerofill", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "smallint unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "smallint(5) unsigned zerofill", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumint unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumint(8) unsigned zerofill", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bigint unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bigint(20) unsigned zerofill", mysqlType) sql = `create table test.t6( @@ -361,17 +362,17 @@ func TestGetMySQLType4IntTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bit", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bit(1)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "bit", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "bit(3)", mysqlType) javaType, err = getJavaSQLType(uint64(65), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -380,9 +381,9 @@ func TestGetMySQLType4IntTypes(t *testing.T) { // bool is identical to tinyint in the TiDB. columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyint", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyint(1)", mysqlType) } @@ -402,9 +403,9 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "float", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "float", mysqlType) javaType, err := getJavaSQLType(3.14, columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -413,9 +414,9 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "double", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "double", mysqlType) javaType, err = getJavaSQLType(2.71, columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -429,16 +430,16 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "float", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "float(10,3)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "float", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "float", mysqlType) sql = `create table test.t3(a int primary key, b double(20, 3))` @@ -449,9 +450,9 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "double", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "double(20,3)", mysqlType) sql = `create table test.t4( @@ -468,9 +469,9 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "float unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "float unsigned", mysqlType) javaType, err = getJavaSQLType(3.14, columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -479,9 +480,9 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "double unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "double unsigned", mysqlType) javaType, err = getJavaSQLType(2.71, columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -489,16 +490,16 @@ func TestGetMySQLType4FloatType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "float unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "float unsigned zerofill", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "double unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "double unsigned zerofill", mysqlType) } @@ -514,16 +515,16 @@ func TestGetMySQLType4Decimal(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(10,0)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(10,0)", mysqlType) sql = `create table test.t2(a int primary key, b decimal(5), c decimal(5, 2))` @@ -534,17 +535,17 @@ func TestGetMySQLType4Decimal(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(5,0)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(5,2)", mysqlType) javaType, err := getJavaSQLType("2333", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -558,17 +559,17 @@ func TestGetMySQLType4Decimal(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal unsigned", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(10,0) unsigned", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "decimal unsigned zerofill", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "decimal(10,0) unsigned zerofill", mysqlType) javaType, err = getJavaSQLType("2333", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -587,17 +588,17 @@ func TestGetMySQLType4TimeTypes(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "time", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "time", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "time", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "time(3)", mysqlType) javaType, err := getJavaSQLType("02:20:20", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -611,17 +612,17 @@ func TestGetMySQLType4TimeTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "datetime", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "datetime", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "datetime", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "datetime(3)", mysqlType) javaType, err = getJavaSQLType("2020-02-20 02:20:20", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -635,17 +636,17 @@ func TestGetMySQLType4TimeTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "timestamp", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "timestamp", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "timestamp", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "timestamp(3)", mysqlType) javaType, err = getJavaSQLType("2020-02-20 02:20:20", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -659,9 +660,9 @@ func TestGetMySQLType4TimeTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "date", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "date", mysqlType) javaType, err = getJavaSQLType("2020-02-20", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -675,17 +676,17 @@ func TestGetMySQLType4TimeTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "year", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "year(4)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "year", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "year(4)", mysqlType) javaType, err = getJavaSQLType("2020", columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -704,17 +705,17 @@ func TestGetMySQLType4Char(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "char", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "char(1)", mysqlType) columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "char", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "char(123)", mysqlType) javaType, err := getJavaSQLType([]uint8("测试char"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -729,9 +730,9 @@ func TestGetMySQLType4Char(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "varchar", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "varchar(123)", mysqlType) javaType, err = getJavaSQLType([]uint8("测试varchar"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -751,9 +752,9 @@ func TestGetMySQLType4TextTypes(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "text", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "text", mysqlType) javaType, err := getJavaSQLType([]uint8("测试text"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -762,9 +763,9 @@ func TestGetMySQLType4TextTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinytext", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinytext", mysqlType) javaType, err = getJavaSQLType([]uint8("测试tinytext"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -773,9 +774,9 @@ func TestGetMySQLType4TextTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[3].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumtext", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumtext", mysqlType) javaType, err = getJavaSQLType([]uint8("测试mediumtext"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -784,9 +785,9 @@ func TestGetMySQLType4TextTypes(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[4].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "longtext", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "longtext", mysqlType) javaType, err = getJavaSQLType([]uint8("测试longtext"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -806,9 +807,9 @@ func TestGetMySQLType4BinaryType(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "binary", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "binary(1)", mysqlType) javaType, err := getJavaSQLType([]uint8("测试binary"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -816,9 +817,9 @@ func TestGetMySQLType4BinaryType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "binary", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "binary(10)", mysqlType) sql = `create table test.t2(a int primary key, b varbinary(23))` @@ -830,9 +831,9 @@ func TestGetMySQLType4BinaryType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "varbinary", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "varbinary(23)", mysqlType) javaType, err = getJavaSQLType([]uint8("测试varbinary"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -852,9 +853,9 @@ func TestGetMySQLType4BlobType(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "blob", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "blob", mysqlType) javaType, err := getJavaSQLType([]uint8("测试blob"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -863,9 +864,9 @@ func TestGetMySQLType4BlobType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "tinyblob", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "tinyblob", mysqlType) javaType, err = getJavaSQLType([]uint8("测试tinyblob"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -874,9 +875,9 @@ func TestGetMySQLType4BlobType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[3].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "mediumblob", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "mediumblob", mysqlType) javaType, err = getJavaSQLType([]uint8("测试mediumblob"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -885,9 +886,9 @@ func TestGetMySQLType4BlobType(t *testing.T) { columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID) require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[4].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "longblob", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "longblob", mysqlType) javaType, err = getJavaSQLType([]uint8("测试longblob"), columnInfo.FieldType.GetType(), flag) require.NoError(t, err) @@ -908,9 +909,9 @@ func TestGetMySQLType4EnumAndSet(t *testing.T) { require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "enum", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "enum('a','b','c')", mysqlType) javaType, err := getJavaSQLType(uint64(1), columnInfo.FieldType.GetType(), flag) @@ -921,9 +922,9 @@ func TestGetMySQLType4EnumAndSet(t *testing.T) { require.True(t, ok) flag = tableInfo.ColumnsFlag[colInfos[2].ID] - mysqlType = getMySQLType(columnInfo, false) + mysqlType = common.GetMySQLType(columnInfo, false) require.Equal(t, "set", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "set('a','b','c')", mysqlType) javaType, err = getJavaSQLType(uint64(2), columnInfo.FieldType.GetType(), flag) @@ -944,9 +945,9 @@ func TestGetMySQLType4JSON(t *testing.T) { columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID) require.True(t, ok) flag := tableInfo.ColumnsFlag[colInfos[1].ID] - mysqlType := getMySQLType(columnInfo, false) + mysqlType := common.GetMySQLType(columnInfo, false) require.Equal(t, "json", mysqlType) - mysqlType = getMySQLType(columnInfo, true) + mysqlType = common.GetMySQLType(columnInfo, true) require.Equal(t, "json", mysqlType) javaType, err := getJavaSQLType("{\"key1\": \"value1\"}", columnInfo.FieldType.GetType(), flag)