Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinRoundWithFracI…
Browse files Browse the repository at this point in the history
…ntSig (pingcap#12103)
  • Loading branch information
tangwz committed Sep 22, 2019
1 parent 8cb488a commit ea557d6
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 @@ -431,3 +431,34 @@ func (b *builtinAbsIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column)
func (b *builtinAbsIntSig) 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 @@ -70,6 +70,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
},
ast.Round: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
{types.ETInt, []types.EvalType{types.ETInt, types.ETInt}, []dataGenerator{nil, &rangeInt64Gener{-100, 100}}},
},
ast.Pow: {
{types.ETReal, []types.EvalType{types.ETReal, types.ETReal}, []dataGenerator{&rangeRealGener{0, 10, 0.5}, &rangeRealGener{0, 100, 0.5}}},
Expand Down

0 comments on commit ea557d6

Please sign in to comment.