Skip to content

Commit

Permalink
rebase and add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Nov 24, 2021
1 parent e7dd3f4 commit 2ba2711
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 4 additions & 3 deletions expression/builtin_convert_charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (b *builtinInternalFromBinarySig) getTransferFunc() func([]byte) ([]byte, e
return transferString
}

// BuildToBinaryFunction to_binary function.
// BuildToBinaryFunction builds to_binary function.
func BuildToBinaryFunction(ctx sessionctx.Context, expr Expression) (res Expression) {
fc := &tidbToBinaryFunctionClass{baseFunctionClass{InternalFuncToBinary, 1, 1}}
f, err := fc.getFunction(ctx, []Expression{expr})
Expand All @@ -241,7 +241,7 @@ func BuildToBinaryFunction(ctx sessionctx.Context, expr Expression) (res Express
return FoldConstant(res)
}

// BuildFromBinaryFunction build from_binary function.
// BuildFromBinaryFunction builds from_binary function.
func BuildFromBinaryFunction(ctx sessionctx.Context, expr Expression, tp *types.FieldType) (res Expression) {
fc := &tidbFromBinaryFunctionClass{baseFunctionClass{InternalFuncFromBinary, 1, 1}, tp}
f, err := fc.getFunction(ctx, []Expression{expr})
Expand Down Expand Up @@ -271,7 +271,8 @@ func HandleBinaryLiteral(ctx sessionctx.Context, expr Expression, ec *ExprCollat
ft.Charset, ft.Collate = ec.Charset, ec.Collation
return BuildFromBinaryFunction(ctx, expr, ft)
}
case ast.Hex, ast.Length, ast.OctetLength, ast.ASCII, ast.ToBase64:
case ast.Hex, ast.Length, ast.OctetLength, ast.ASCII, ast.ToBase64, ast.AesDecrypt, ast.Decode, ast.Encode,
ast.PasswordFunc, ast.MD5, ast.SHA, ast.SHA1, ast.SHA2, ast.Compress:
if _, err := charset.GetDefaultCollationLegacy(expr.GetType().Charset); err != nil {
return BuildToBinaryFunction(ctx, expr)
}
Expand Down
2 changes: 1 addition & 1 deletion expression/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func safeConvert(ctx sessionctx.Context, ec *ExprCollation, args ...Expression)
continue
}

// if value has ASCII repertoire, or it is binary string, just skip it.
// If value has ASCII repertoire, or it is binary string, just skip it.
if arg.Repertoire() == ASCII || types.IsBinaryStr(arg.GetType()) {
continue
}
Expand Down
7 changes: 3 additions & 4 deletions expression/constant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,13 @@ func TestConstantFoldingCharsetConvert(t *testing.T) {
newString("中文", "binary"))),
result: "中文",
},
// The result is binary charset, so gbk constant will convert to binary which is \xd6\xd0\xce\xc4.
{
condition: newFunction(ast.Concat,
newFunctionWithType(
InternalFuncFromBinary, types.NewFieldTypeWithCollation(mysql.TypeVarchar, "gbk_bin", -1),
newString("\xd2\xbb", "binary")),
newString("中文", "gbk_bin"),
newString("\xd2\xbb", "binary"),
),
result: "一中文",
result: "\xd6\xd0\xce\xc4\xd2\xbb",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 2ba2711

Please sign in to comment.