From 2865b81244cfdb545abcb4491173aed75855a291 Mon Sep 17 00:00:00 2001 From: Iggie Wang <54307176+hey-kong@users.noreply.github.com> Date: Tue, 8 Oct 2019 16:29:46 +0800 Subject: [PATCH] expression: implement vectorized evaluation for `builtinArithmeticMultiplyRealSig` (#12543) --- expression/builtin_arithmetic_vec.go | 29 +++++++++++++++++++++-- expression/builtin_arithmetic_vec_test.go | 8 ++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/expression/builtin_arithmetic_vec.go b/expression/builtin_arithmetic_vec.go index 69d7d9a56fa18..87fcaf643979d 100644 --- a/expression/builtin_arithmetic_vec.go +++ b/expression/builtin_arithmetic_vec.go @@ -23,11 +23,36 @@ import ( ) func (b *builtinArithmeticMultiplyRealSig) vectorized() bool { - return false + return true } func (b *builtinArithmeticMultiplyRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil { + return err + } + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETReal, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[1].VecEvalReal(b.ctx, input, buf); err != nil { + return err + } + + result.MergeNulls(buf) + x := result.Float64s() + y := buf.Float64s() + for i := 0; i < n; i++ { + if result.IsNull(i) { + continue + } + x[i] = x[i] * y[i] + if math.IsInf(x[i], 0) { + return types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s * %s)", b.args[0].String(), b.args[1].String())) + } + } + return nil } func (b *builtinArithmeticDivideDecimalSig) vectorized() bool { diff --git a/expression/builtin_arithmetic_vec_test.go b/expression/builtin_arithmetic_vec_test.go index e7661cc18ecfa..92ebd4330ba88 100644 --- a/expression/builtin_arithmetic_vec_test.go +++ b/expression/builtin_arithmetic_vec_test.go @@ -30,9 +30,11 @@ var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{ ast.IntDiv: {}, ast.Mod: {}, ast.Or: {}, - ast.Mul: {}, - ast.Round: {}, - ast.And: {}, + ast.Mul: { + {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, + }, + ast.Round: {}, + ast.And: {}, ast.Plus: { {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, },