expression: implement vectorized evaluation for builtinCastStringAsTimeSig (#12947)

This commit is contained in:
Eugene Kalinin
2019-11-01 11:01:06 +03:00
committed by pingcap-github-bot
parent e4856f07fb
commit 3a074d4bf8
2 changed files with 41 additions and 2 deletions

View File

@ -1092,11 +1092,44 @@ func (b *builtinCastStringAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, resul
}
func (b *builtinCastStringAsTimeSig) vectorized() bool {
return false
return true
}
func (b *builtinCastStringAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}
result.ResizeTime(n, false)
result.MergeNulls(buf)
times := result.Times()
stmtCtx := b.ctx.GetSessionVars().StmtCtx
fsp := int8(b.tp.Decimal)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
tm, err := types.ParseTime(stmtCtx, buf.GetString(i), b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
continue
}
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)
}
}
return nil
}
func (b *builtinCastDecimalAsIntSig) vectorized() bool {

View File

@ -59,6 +59,12 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETString},
geners: []dataGenerator{
&dataTimeStrGener{},
&timeStrGener{},
&dataStrGener{},
}},
},
}