Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinAbsIntSig (pin…
Browse files Browse the repository at this point in the history
  • Loading branch information
tangwz committed Sep 22, 2019
1 parent f792e8d commit c25ae50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,26 @@ func (b *builtinPowSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) er
func (b *builtinPowSig) vectorized() bool {
return true
}

func (b *builtinAbsIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}
i64s := result.Int64s()
for i := 0; i < len(i64s); i++ {
if result.IsNull(i) {
continue
}
if i64s[i] == math.MinInt64 {
return types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("abs(%d)", i64s[i]))
}
if i64s[i] < 0 {
i64s[i] = -i64s[i]
}
}
return nil
}

func (b *builtinAbsIntSig) 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 @@ -60,6 +60,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
},
ast.Abs: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
{types.ETInt, []types.EvalType{types.ETInt}, nil},
},
ast.Round: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
Expand Down

0 comments on commit c25ae50

Please sign in to comment.