Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinCastDecimalA…
Browse files Browse the repository at this point in the history
…sDecimalSig` (pingcap#12102)
  • Loading branch information
catror committed Nov 14, 2019
1 parent ec95f91 commit d600fb7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
34 changes: 32 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,41 @@ func (b *builtinCastRealAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
}

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

func (b *builtinCastDecimalAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDecimal, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalDecimal(b.ctx, input, buf); err != nil {
return err
}

result.ResizeDecimal(n, false)
result.MergeNulls(buf)
oldDecs := buf.Decimals()
newDecs := result.Decimals()
sc := b.ctx.GetSessionVars().StmtCtx
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}

dec := &types.MyDecimal{}
if !(b.inUnion && mysql.HasUnsignedFlag(b.tp.Flag) && oldDecs[i].IsNegative()) {
*dec = oldDecs[i]
}
dec, err = types.ProduceDecWithSpecifiedTp(dec, b.tp, sc)
if err != nil {
return err
}
newDecs[i] = *dec
}
return nil
}

func (b *builtinCastDurationAsTimeSig) vectorized() bool {
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
geners: []dataGenerator{
&jsonTimeGener{},
}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}},
},
}

Expand Down

0 comments on commit d600fb7

Please sign in to comment.