Skip to content

Commit

Permalink
expression: implement vectorized evaluation for ‘builtinFloorDecToDec…
Browse files Browse the repository at this point in the history
…Sig’ (#13409)
  • Loading branch information
Zhuchengyu04 authored and qw4990 committed Nov 16, 2019
1 parent 3ba0b4c commit d8022f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,38 @@ func (b *builtinCeilDecToDecSig) vecEvalDecimal(input *chunk.Chunk, result *chun
}

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

func (b *builtinFloorDecToDecSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
if err := b.args[0].VecEvalDecimal(b.ctx, input, result); err != nil {
return err
}
ds := result.Decimals()

for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
rst := new(types.MyDecimal)
if !ds[i].IsNegative() {
if err := ds[i].Round(rst, 0, types.ModeTruncate); err != nil {
return err
}
} else {
if err := ds[i].Round(rst, 0, types.ModeTruncate); err != nil {
return err
}
if rst.Compare(&ds[i]) != 0 {
if err := types.DecimalSub(rst, types.NewDecFromInt(1), rst); err != nil {
return err
}
}
}
ds[i] = *rst
}
return nil
}

func (b *builtinTruncateDecimalSig) vectorized() bool {
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_math_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal}, geners: nil},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}, geners: nil},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}}, geners: nil},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}, childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeNewDecimal, Flen: 32, Decimal: 2}}, geners: nil},
},
ast.Ceil: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}, geners: nil},
Expand Down

0 comments on commit d8022f7

Please sign in to comment.