From 2ba27115cd7f53cfd7062cd9ccbac67dcc14305e Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Wed, 24 Nov 2021 15:21:00 +0800 Subject: [PATCH] rebase and add more test --- expression/builtin_convert_charset.go | 7 ++++--- expression/collation.go | 2 +- expression/constant_test.go | 7 +++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/expression/builtin_convert_charset.go b/expression/builtin_convert_charset.go index 83a92199a6521..aac9d1680ddda 100644 --- a/expression/builtin_convert_charset.go +++ b/expression/builtin_convert_charset.go @@ -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}) @@ -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}) @@ -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) } diff --git a/expression/collation.go b/expression/collation.go index cb83f2c50505b..80a2720c8cfe4 100644 --- a/expression/collation.go +++ b/expression/collation.go @@ -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 } diff --git a/expression/constant_test.go b/expression/constant_test.go index fa38c19252061..62f03140b61f7 100644 --- a/expression/constant_test.go +++ b/expression/constant_test.go @@ -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 {