diff --git a/expression/builtin_encryption_vec.go b/expression/builtin_encryption_vec.go index 036545eae0f0d..4f9b4284dbf19 100644 --- a/expression/builtin_encryption_vec.go +++ b/expression/builtin_encryption_vec.go @@ -14,6 +14,9 @@ package expression import ( + "crypto/sha1" + "fmt" + "github.com/pingcap/errors" "github.com/pingcap/parser/auth" "github.com/pingcap/tidb/types" @@ -198,11 +201,35 @@ func (b *builtinPasswordSig) vecEvalString(input *chunk.Chunk, result *chunk.Col } func (b *builtinSHA1Sig) vectorized() bool { - return false + return true } func (b *builtinSHA1Sig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETString, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil { + return err + } + result.ReserveString(n) + hasher := sha1.New() + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + str := buf.GetBytes(i) + _, err = hasher.Write(str) + if err != nil { + return err + } + result.AppendString(fmt.Sprintf("%x", hasher.Sum(nil))) + hasher.Reset() + } + return nil } func (b *builtinUncompressSig) vectorized() bool { diff --git a/expression/builtin_encryption_vec_test.go b/expression/builtin_encryption_vec_test.go index 36113376667cb..dffa81b9fee00 100644 --- a/expression/builtin_encryption_vec_test.go +++ b/expression/builtin_encryption_vec_test.go @@ -22,15 +22,18 @@ import ( ) var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{ - ast.AesEncrypt: {}, - ast.Uncompress: {}, - ast.AesDecrypt: {}, - ast.Compress: {}, - ast.MD5: {}, - ast.SHA: {}, + ast.AesEncrypt: {}, + ast.Uncompress: {}, + ast.AesDecrypt: {}, + ast.Compress: {}, + ast.MD5: {}, + ast.SHA: { + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}}}, ast.RandomBytes: {}, ast.UncompressedLength: {}, - ast.SHA1: {}, + ast.SHA1: { + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}}, + }, ast.PasswordFunc: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&randLenStrGener{10, 20}}}, },