diff --git a/plugin/mysql/src/transfer.go b/plugin/mysql/src/transfer.go index 167658d..9bb99b3 100644 --- a/plugin/mysql/src/transfer.go +++ b/plugin/mysql/src/transfer.go @@ -149,15 +149,15 @@ func (This *Conn) TransferToTypeByColumnType_Starrocks(columnType string, nullab toType = "VARCHAR(20)" case "int64": toType = "BIGINT(20)" - case "uint32", "uint24": + case "uint32": toType = "BIGINT(20)" - case "int32", "int24": + case "int32", "int24", "uint24": toType = "INT(11)" case "uint16": toType = "INT(11)" case "int16", "year(4)", "year(2)", "year": toType = "SMALLINT(6)" - case "uint8", "SMALLINT(uint8)": + case "uint8": toType = "SMALLINT(6)" case "int8", "bool": toType = "TINYINT(4)" @@ -227,7 +227,11 @@ func (This *Conn) TransferToTypeByColumnType_Starrocks(columnType string, nullab if lenStr == "" { toType = "VARCHAR(255)" } else { - toType = fmt.Sprintf("CHAR(%s)", lenStr) + if i == 0 { + toType = fmt.Sprintf("CHAR(%s)", lenStr) + } else { + toType = fmt.Sprintf("VARCHAR(%s)", lenStr) + } } break } diff --git a/plugin/mysql/src/transfer_test.go b/plugin/mysql/src/transfer_test.go new file mode 100644 index 0000000..fa23503 --- /dev/null +++ b/plugin/mysql/src/transfer_test.go @@ -0,0 +1,183 @@ +package src + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestTransferToTypeByColumnType_Starrocks(t *testing.T) { + type ColumnTypeStruct struct { + columnTypeList []string + nullable bool + destColumnType string + } + var caseList = []ColumnTypeStruct{ + { + columnTypeList: []string{"uint64"}, + nullable: false, + destColumnType: "VARCHAR(20)", + }, + { + columnTypeList: []string{"int64", "uint32"}, + nullable: false, + destColumnType: "BIGINT(20)", + }, + { + columnTypeList: []string{"int32", "uint24", "int24", "uint16"}, + nullable: false, + destColumnType: "INT(11)", + }, + { + columnTypeList: []string{"int16", "year(4)", "year(2)", "year", "uint8"}, + nullable: false, + destColumnType: "SMALLINT(6)", + }, + { + columnTypeList: []string{"int8", "bool"}, + nullable: false, + destColumnType: "TINYINT(4)", + }, + { + columnTypeList: []string{"float"}, + nullable: false, + destColumnType: "FLOAT", + }, + { + columnTypeList: []string{"double", "real"}, + nullable: false, + destColumnType: "DOUBLE", + }, + { + columnTypeList: []string{"decimal", "numeric"}, + nullable: false, + destColumnType: "DECIMAL", + }, + { + columnTypeList: []string{"decimal(9,2)"}, + nullable: false, + destColumnType: "Decimal(9,2)", + }, + { + columnTypeList: []string{"decimal(19,5)"}, + nullable: false, + destColumnType: "Decimal(19,5)", + }, + { + columnTypeList: []string{"decimal(38,2)"}, + nullable: false, + destColumnType: "Decimal(38,2)", + }, + { + columnTypeList: []string{"decimal(39,2)"}, + nullable: false, + destColumnType: "VARCHAR(78)", + }, + { + columnTypeList: []string{"decimal(88,2)"}, + nullable: false, + destColumnType: "VARCHAR(255)", + }, + { + columnTypeList: []string{"date", "Nullable(date)"}, + nullable: false, + destColumnType: "DATE", + }, + { + columnTypeList: []string{"json"}, + nullable: false, + destColumnType: "JSON", + }, + { + columnTypeList: []string{"time"}, + nullable: false, + destColumnType: "VARCHAR(10)", + }, + { + columnTypeList: []string{"enum"}, + nullable: false, + destColumnType: "VARCHAR(255)", + }, + { + columnTypeList: []string{"set"}, + nullable: false, + destColumnType: "VARCHAR(2048)", + }, + { + columnTypeList: []string{"string", "longblob", "longtext"}, + nullable: false, + destColumnType: "VARCHAR(163841)", + }, + { + columnTypeList: []string{"double(9,2)", "real(10,2)"}, + nullable: false, + destColumnType: "DOUBLE", + }, + { + columnTypeList: []string{"float(9,2)"}, + nullable: false, + destColumnType: "FLOAT", + }, + { + columnTypeList: []string{"bit"}, + nullable: false, + destColumnType: "BIGINT(20)", + }, + { + columnTypeList: []string{"timestamp(6)", "datetime(3)"}, + nullable: false, + destColumnType: "DATETIME", + }, + { + columnTypeList: []string{"time(6)", "time(1)"}, + nullable: false, + destColumnType: "VARCHAR(16)", + }, + { + columnTypeList: []string{"enum('a','b')"}, + nullable: false, + destColumnType: "VARCHAR(255)", + }, + { + columnTypeList: []string{"set('a','b')"}, + nullable: false, + destColumnType: "VARCHAR(2048)", + }, + { + columnTypeList: []string{"char(1)"}, + nullable: false, + destColumnType: "CHAR(1)", + }, + { + columnTypeList: []string{"char(255)"}, + nullable: false, + destColumnType: "CHAR(255)", + }, + { + columnTypeList: []string{"varchar(500)"}, + nullable: false, + destColumnType: "VARCHAR(500)", + }, + + { + columnTypeList: []string{"Nullable(varchar(500))"}, + nullable: false, + destColumnType: "VARCHAR(500)", + }, + { + columnTypeList: []string{"Nullable(int64)"}, + nullable: true, + destColumnType: "BIGINT(20) DEFAULT NULL", + }, + } + + c := &Conn{} + for _, caseInfo := range caseList { + for _, columnType := range caseInfo.columnTypeList { + Convey(caseInfo.destColumnType, t, func() { + toDestColumnType := c.TransferToTypeByColumnType_Starrocks(columnType, caseInfo.nullable) + So(toDestColumnType, ShouldEqual, caseInfo.destColumnType) + }) + } + } +} diff --git a/plugin/mysql/src/version.go b/plugin/mysql/src/version.go index 26d8973..9fe92f4 100644 --- a/plugin/mysql/src/version.go +++ b/plugin/mysql/src/version.go @@ -1,4 +1,4 @@ package src -const VERSION = "v2.2.0" -const BIFROST_VERION = "v2.2.0" +const VERSION = "v2.3.5" +const BIFROST_VERION = "v2.3.4"