Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinDecode… (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyj authored and zz-jason committed Oct 16, 2019
1 parent 73c172a commit 46c3f1a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
35 changes: 33 additions & 2 deletions expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,42 @@ func (b *builtinAesEncryptIVSig) vecEvalString(input *chunk.Chunk, result *chunk
}

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

func (b *builtinDecodeSig) 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
}
buf1, err1 := b.bufAllocator.get(types.ETString, n)
if err1 != nil {
return err1
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalString(b.ctx, input, buf1); err != nil {
return err
}
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) || buf1.IsNull(i) {
result.AppendNull()
continue
}
dataStr := buf.GetString(i)
passwordStr := buf1.GetString(i)
decodeStr, err := encrypt.SQLDecode(dataStr, passwordStr)
if err != nil {
return err
}
result.AppendString(decodeStr)
}
return nil
}

func (b *builtinEncodeSig) vectorized() bool {
Expand Down
3 changes: 3 additions & 0 deletions expression/builtin_encryption_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
ast.Encode: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
},
ast.Decode: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}, geners: []dataGenerator{&randLenStrGener{10, 20}}},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinEncryptionFunc(c *C) {
Expand Down

0 comments on commit 46c3f1a

Please sign in to comment.