Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: implement vectorized evaluation for builtinLowerStr #12013

Merged
merged 11 commits into from
Sep 11, 2019
25 changes: 22 additions & 3 deletions expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ var vecExprBenchCases = map[string][]vecExprBenchCase{
ast.Cast: {
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
{types.ETInt, []types.EvalType{types.ETInt}},
},
ast.Lower: {
{types.ETString, []types.EvalType{types.ETString}},
},
ast.Log10: {
{types.ETReal, []types.EvalType{types.ETReal}},
},
Expand Down Expand Up @@ -286,14 +289,30 @@ func fillColumn(eType types.EvalType, chk *chunk.Chunk, colIdx int) {
if rand.Float64() < nullRatio {
chk.AppendNull(colIdx)
} else {
chk.AppendString(colIdx, fmt.Sprintf("%v", rand.Int()))
chk.AppendString(colIdx, randString())
}
}
default:
panic(fmt.Sprintf("EvalType=%v is not supported.", eType))
}
}

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 Expand Up @@ -535,7 +554,7 @@ func (s *testEvaluatorSuite) TestVectorizedBuiltinFunc(c *C) {
err := baseFunc.vecEvalJSON(input, output)
c.Assert(err, IsNil)
for row := it.Begin(); row != it.End(); row = it.Next() {
val, isNull, err := baseFunc.evalDuration(row)
val, isNull, err := baseFunc.evalJSON(row)
c.Assert(err, IsNil)
c.Assert(isNull, Equals, output.IsNull(i))
if !isNull {
Expand All @@ -547,7 +566,7 @@ func (s *testEvaluatorSuite) TestVectorizedBuiltinFunc(c *C) {
err := baseFunc.vecEvalString(input, output)
c.Assert(err, IsNil)
for row := it.Begin(); row != it.End(); row = it.Next() {
val, isNull, err := baseFunc.evalDuration(row)
val, isNull, err := baseFunc.evalString(row)
c.Assert(err, IsNil)
c.Assert(isNull, Equals, output.IsNull(i))
if !isNull {
Expand Down
49 changes: 49 additions & 0 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
"unicode/utf8"
)

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)
zz-jason marked this conversation as resolved.
Show resolved Hide resolved
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
}