Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinMD5Sig (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyj authored and qw4990 committed Oct 22, 2019
1 parent 2d28a27 commit 263a49d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 27 additions & 2 deletions expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package expression

import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
Expand Down Expand Up @@ -138,11 +139,35 @@ func (b *builtinRandomBytesSig) vecEvalString(input *chunk.Chunk, result *chunk.
}

func (b *builtinMD5Sig) vectorized() bool {
return false
return true
}

func (b *builtinMD5Sig) 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)
digest := md5.New()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
cryptByte := buf.GetBytes(i)
_, err := digest.Write(cryptByte)
if err != nil {
return err
}
result.AppendString(fmt.Sprintf("%x", digest.Sum(nil)))
digest.Reset()
}
return nil
}

func (b *builtinSHA2Sig) vectorized() bool {
Expand Down
4 changes: 3 additions & 1 deletion expression/builtin_encryption_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
ast.Uncompress: {},
ast.AesDecrypt: {},
ast.Compress: {},
ast.MD5: {},
ast.MD5: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
},
ast.SHA: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
},
Expand Down

0 comments on commit 263a49d

Please sign in to comment.