From ea557d67ba24bc29cc76993300e7b453c9f2253f Mon Sep 17 00:00:00 2001 From: tangwz Date: Sun, 22 Sep 2019 20:57:26 +0800 Subject: [PATCH] expression: implement vectorized evaluation for builtinRoundWithFracIntSig (#12103) --- expression/builtin_math_vec.go | 31 +++++++++++++++++++++++++++++ expression/builtin_math_vec_test.go | 1 + 2 files changed, 32 insertions(+) diff --git a/expression/builtin_math_vec.go b/expression/builtin_math_vec.go index f9ef68926deb8..1891cdd91113e 100644 --- a/expression/builtin_math_vec.go +++ b/expression/builtin_math_vec.go @@ -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 +} diff --git a/expression/builtin_math_vec_test.go b/expression/builtin_math_vec_test.go index efead2fe9c94b..1bd5ea97e9ef6 100644 --- a/expression/builtin_math_vec_test.go +++ b/expression/builtin_math_vec_test.go @@ -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}}},