Skip to content

Commit

Permalink
expression: implement vectorized evaluation for "builtinCastIntAsStri…
Browse files Browse the repository at this point in the history
…ngSig" (#12425)
  • Loading branch information
tsthght authored and sre-bot committed Oct 1, 2019
1 parent ea6d00b commit 4b1a43e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
45 changes: 43 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package expression

import (
"strconv"

"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -265,11 +267,50 @@ func (b *builtinCastDurationAsTimeSig) vecEvalTime(input *chunk.Chunk, result *c
}

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

func (b *builtinCastIntAsStringSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalInt(b.ctx, input, buf); err != nil {
return err
}

isUnsigned := mysql.HasUnsignedFlag(b.args[0].GetType().Flag)
result.ReserveString(n)
i64s := buf.Int64s()
for i := 0; i < n; i++ {
var str string
if buf.IsNull(i) {
result.AppendNull()
continue
}
if !isUnsigned {
str = strconv.FormatInt(i64s[i], 10)
} else {
str = strconv.FormatUint(uint64(i64s[i]), 10)
}
str, err = types.ProduceStrWithSpecifiedTp(str, b.tp, b.ctx.GetSessionVars().StmtCtx, false)
if err != nil {
return err
}
var d bool
str, d, err = padZeroForBinaryType(str, b.tp, b.ctx)
if err != nil {
return err
}
if d {
result.AppendNull()
} else {
result.AppendString(str)
}
}
return nil
}

func (b *builtinCastRealAsIntSig) vectorized() bool {
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
fsp: 1,
}},
},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDatetime}},
},
}
Expand Down

0 comments on commit 4b1a43e

Please sign in to comment.