Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinLowerStr (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored and sre-bot committed Sep 11, 2019
1 parent ffc3482 commit 4b6c38d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
18 changes: 17 additions & 1 deletion expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (g *defaultGener) gen() interface{} {
}
return *j
case types.ETString:
return fmt.Sprintf("%v", rand.Int())
return randString()
}
return nil
}
Expand Down Expand Up @@ -327,6 +327,22 @@ func fillColumn(eType types.EvalType, chk *chunk.Chunk, colIdx int, testCase vec
}
}

func randString() string {
n := 10 + rand.Intn(10)
buf := make([]byte, n)
for i := range buf {
x := rand.Intn(62)
if x < 10 {
buf[i] = byte('0' + x)
} else if x-10 < 26 {
buf[i] = byte('a' + x - 10)
} else {
buf[i] = byte('A' + x - 10 - 26)
}
}
return string(buf)
}

func eType2FieldType(eType types.EvalType) *types.FieldType {
switch eType {
case types.ETInt:
Expand Down
43 changes: 43 additions & 0 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package expression

import (
"math"
"strings"
"unicode/utf8"

"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
)

func (b *builtinLowerSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalString(b.ctx, input, result); err != nil {
return err
}
if types.IsBinaryStr(b.args[0].GetType()) {
return nil
}

Loop:
for i := 0; i < input.NumRows(); i++ {
str := result.GetBytes(i)
for _, c := range str {
if c >= utf8.RuneSelf {
continue Loop
}
}
for i := range str {
if str[i] >= 'A' && str[i] <= 'Z' {
str[i] += 'a' - 'A'
}
}
}
return nil
}

func (b *builtinLowerSig) vectorized() bool {
return true
}

func (b *builtinRepeatSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
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 @@ -25,6 +25,9 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
ast.Repeat: {
{types.ETString, []types.EvalType{types.ETString, types.ETInt}, []dataGenerator{&randLenStrGener{10, 20}, &rangeInt64Gener{-10, 10}}},
},
ast.Lower: {
{types.ETString, []types.EvalType{types.ETString}, nil},
},
}

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

0 comments on commit 4b6c38d

Please sign in to comment.