Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinRoundWithFrac…
Browse files Browse the repository at this point in the history
…IntSig` (pingcap#12299)
  • Loading branch information
tangwz authored and ngaut committed Sep 24, 2019
1 parent bb5b0c8 commit ca41cde
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,34 @@ func (b *builtinRoundIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column
func (b *builtinRoundIntSig) vectorized() bool {
return true
}

func (b *builtinRoundWithFracIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
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
}

i64s := result.Int64s()
frac := buf.Int64s()
result.MergeNulls(buf)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
i64s[i] = int64(types.Round(float64(i64s[i]), int(frac[i])))
}
return nil
}

func (b *builtinRoundWithFracIntSig) vectorized() bool {
return true
}
1 change: 1 addition & 0 deletions expression/builtin_math_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
ast.Round: {
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-100, 100}}},
},
ast.Pow: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{&rangeRealGener{0, 10, 0.5}, &rangeRealGener{0, 100, 0.5}}},
Expand Down

0 comments on commit ca41cde

Please sign in to comment.