expression: implement vectorized evaluation for builtinTruncateIntSig (#12474)

This commit is contained in:
ZOULAIZOUQU
2019-09-30 15:15:08 +08:00
committed by pingcap-github-bot
parent a3d4f898c5
commit 230e72e699
2 changed files with 30 additions and 2 deletions

View File

@ -697,11 +697,38 @@ func (b *builtinCeilIntToDecSig) vecEvalDecimal(input *chunk.Chunk, result *chun
}
func (b *builtinTruncateIntSig) vectorized() bool {
return false
return true
}
func (b *builtinTruncateIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}
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[1].VecEvalInt(b.ctx, input, buf); err != nil {
return err
}
result.MergeNulls(buf)
i64s := result.Int64s()
buf64s := buf.Int64s()
for i := 0; i < len(i64s); i++ {
if result.IsNull(i) {
continue
}
if buf64s[i] < 0 {
shift := int64(math.Pow10(int(-buf64s[i])))
i64s[i] = i64s[i] / shift * shift
}
}
return nil
}
func (b *builtinTruncateUintSig) vectorized() bool {

View File

@ -97,6 +97,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
},
ast.Truncate: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}},
},
}