Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinCastTimeAsTime…
Browse files Browse the repository at this point in the history
…Sig (#13209)
  • Loading branch information
ekalinin authored and sre-bot committed Nov 11, 2019
1 parent 69ff2d5 commit 1938cd1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 33 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,42 @@ func (b *builtinCastTimeAsIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.C
}

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

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

times := result.Times()
stmt := b.ctx.GetSessionVars().StmtCtx
fsp := int8(b.tp.Decimal)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
res, err := times[i].Convert(stmt, b.tp.Tp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
continue
}
tm, err := res.RoundFrac(stmt, fsp)
if err != nil {
return err
}
times[i] = tm
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
times[i].Time = types.FromDate(tm.Time.Year(), tm.Time.Month(), tm.Time.Day(), 0, 0, 0, 0)
times[i].Type = b.tp.Tp
}
}
return nil
}

func (b *builtinCastTimeAsStringSig) vectorized() bool {
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
&dataStrGener{},
}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETTimestamp}},
},
}

Expand Down

0 comments on commit 1938cd1

Please sign in to comment.