Skip to content

Commit

Permalink
fix all unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
3AceShowHand committed Nov 21, 2023
1 parent fc574fc commit 9b5128d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
15 changes: 2 additions & 13 deletions pkg/sink/codec/canal/canal_json_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/pingcap/log"
timodel "github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/types"
"github.com/pingcap/tiflow/cdc/model"
cerrors "github.com/pingcap/tiflow/pkg/errors"
"github.com/pingcap/tiflow/pkg/sink/codec/utils"
canal "github.com/pingcap/tiflow/proto/canal"
"go.uber.org/zap"
"golang.org/x/text/encoding/charmap"
Expand Down Expand Up @@ -213,19 +213,8 @@ func canalJSONColumnMap2RowChangeColumns(cols map[string]interface{}, mysqlType
return result, nil
}

func extractBasicMySQLType(mysqlType string) string {
for i := 0; i < len(mysqlType); i++ {
if mysqlType[i] == '(' || mysqlType[i] == ' ' {
return mysqlType[:i]
}
}
return mysqlType
}

func canalJSONFormatColumn(value interface{}, name string, mysqlTypeStr string) *model.Column {
mysqlTypeStr = extractBasicMySQLType(mysqlTypeStr)
mysqlType := types.StrToType(mysqlTypeStr)

mysqlType := utils.ExtractBasicMySQLType(mysqlTypeStr)
result := &model.Column{
Type: mysqlType,
Name: name,
Expand Down
18 changes: 16 additions & 2 deletions pkg/sink/codec/utils/field_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ package utils
import (
"strings"

"github.com/pingcap/tidb/parser/charset"
timodel "github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/parser/types"
"github.com/pingcap/tiflow/cdc/model"
)

// SetBinChsClnFlag set the binary charset flag.
func SetBinChsClnFlag(ft *types.FieldType) *types.FieldType {
types.SetBinChsClnFlag(ft)
ft.SetCharset(charset.CharsetBin)
ft.SetCollate(charset.CollationBin)
ft.AddFlag(mysql.BinaryFlag)
return ft
}

Expand Down Expand Up @@ -66,3 +69,14 @@ func GetMySQLType(columnInfo *timodel.ColumnInfo, fullType bool) string {
}
return columnInfo.GetTypeDesc()
}

// ExtractBasicMySQLType return the mysql type
func ExtractBasicMySQLType(mysqlType string) byte {
for i := 0; i < len(mysqlType); i++ {
if mysqlType[i] == '(' || mysqlType[i] == ' ' {
return types.StrToType(mysqlType[:i])
}
}

return types.StrToType(mysqlType)
}

0 comments on commit 9b5128d

Please sign in to comment.