Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinArithmeticMul…
Browse files Browse the repository at this point in the history
…tiplyRealSig` (#12543)
  • Loading branch information
hey-kong authored and sre-bot committed Oct 8, 2019
1 parent 3e8129d commit 2865b81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 27 additions & 2 deletions expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions expression/builtin_arithmetic_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
Expand Down

0 comments on commit 2865b81

Please sign in to comment.