Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinReplaceSig (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored and sre-bot committed Sep 30, 2019
1 parent 230e72e commit b707447
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
48 changes: 46 additions & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,55 @@ func (b *builtinCharSig) vecEvalString(input *chunk.Chunk, result *chunk.Column)
}

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

// evalString evals a builtinReplaceSig.
// See https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace
func (b *builtinReplaceSig) 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, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalString(b.ctx, input, buf1); err != nil {
return err
}
buf2, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf2)
if err := b.args[2].VecEvalString(b.ctx, input, buf2); err != nil {
return err
}

result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) || buf1.IsNull(i) || buf2.IsNull(i) {
result.AppendNull()
continue
}
str := buf.GetString(i)
oldStr := buf1.GetString(i)
newStr := buf2.GetString(i)
if oldStr == "" {
result.AppendString(str)
continue
}
str = strings.Replace(str, oldStr, newStr, -1)
result.AppendString(str)
}
return nil
}

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

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

0 comments on commit b707447

Please sign in to comment.