Skip to content

Commit

Permalink
expression:implement vectorized evaluation for builtinConvertSig (pin…
Browse files Browse the repository at this point in the history
  • Loading branch information
icditwang authored and qw4990 committed Nov 27, 2019
1 parent 01a9e13 commit a85a9f9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
36 changes: 34 additions & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"golang.org/x/text/transform"
)

func (b *builtinLowerSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
Expand Down Expand Up @@ -599,11 +601,41 @@ func (b *builtinConcatWSSig) vecEvalString(input *chunk.Chunk, result *chunk.Col
}

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

func (b *builtinConvertSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
expr, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(expr)
if err := b.args[0].VecEvalString(b.ctx, input, expr); err != nil {
return err
}
// Since charset is already validated and set from getFunction(), there's no
// need to get charset from args again.
encoding, _ := charset.Lookup(b.tp.Charset)
// However, if `b.tp.Charset` is abnormally set to a wrong charset, we still
// return with error.
if encoding == nil {
return errUnknownCharacterSet.GenWithStackByArgs(b.tp.Charset)
}
result.ReserveString(n)
for i := 0; i < n; i++ {
if expr.IsNull(i) {
result.AppendNull()
continue
}
exprI := expr.GetString(i)
target, _, err := transform.String(encoding.NewDecoder(), exprI)
if err != nil {
return err
}
result.AppendString(target)
}
return nil
}

func (b *builtinSubstringIndexSig) vectorized() bool {
Expand Down
23 changes: 22 additions & 1 deletion expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,28 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}},
},
ast.ConcatWS: {},
ast.Convert: {},
ast.Convert: {
{
retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString},
constants: []*Constant{nil, {Value: types.NewDatum("utf8"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{
retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString},
constants: []*Constant{nil, {Value: types.NewDatum("binary"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{
retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString},
constants: []*Constant{nil, {Value: types.NewDatum("utf8mb4"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{
retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString},
constants: []*Constant{nil, {Value: types.NewDatum("ascii"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{
retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString},
constants: []*Constant{nil, {Value: types.NewDatum("latin1"), RetType: types.NewFieldType(mysql.TypeString)}},
},
},
ast.Substring: {
{
retEvalType: types.ETString,
Expand Down

0 comments on commit a85a9f9

Please sign in to comment.