Skip to content

Commit

Permalink
expression: implement vecEval for ArithmeticDivideRealSig (pingcap#12546
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hey-kong authored and XuHuaiyu committed Oct 9, 2019
1 parent 0237e02 commit f6c019c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (g *rangeRealGener) gen() interface{} {
if rand.Float64() < g.nullRation {
return nil
}
if g.end <= g.begin {
if g.end < g.begin {
g.begin = -100
g.end = 100
}
Expand Down
37 changes: 35 additions & 2 deletions expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,44 @@ func (b *builtinArithmeticMultiplyIntSig) vecEvalInt(input *chunk.Chunk, result
}

func (b *builtinArithmeticDivideRealSig) vectorized() bool {
return false
return true
}

func (b *builtinArithmeticDivideRealSig) 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
}
if y[i] == 0 {
if err := handleDivisionByZeroError(b.ctx); err != nil {
return err
}
result.SetNull(i, true)
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 *builtinArithmeticIntDivideIntSig) vectorized() bool {
Expand Down
5 changes: 4 additions & 1 deletion expression/builtin_arithmetic_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ var vecBuiltinArithmeticCases = map[string][]vecExprBenchCase{
ast.Minus: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
},
ast.Div: {},
ast.Div: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, &rangeRealGener{0, 0, 0}}},
},
ast.IntDiv: {},
ast.Mod: {},
ast.Or: {},
Expand Down

0 comments on commit f6c019c

Please sign in to comment.