Skip to content

Commit

Permalink
fixed output starrocks varchar(255) tansfer error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jc3wish committed Feb 25, 2024
1 parent 5d76896 commit 064c5bd
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 6 deletions.
12 changes: 8 additions & 4 deletions plugin/mysql/src/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
}
Expand Down
183 changes: 183 additions & 0 deletions plugin/mysql/src/transfer_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
}
4 changes: 2 additions & 2 deletions plugin/mysql/src/version.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 064c5bd

Please sign in to comment.