Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: implement vectorized evaluation for builtinCastDurationAsTimeSig #13244

Merged
merged 8 commits into from
Nov 8, 2019
Next Next commit
expression: implement vectorized evaluation for builtinCastDurationAs…
…TimeSig
  • Loading branch information
ekalinin committed Nov 7, 2019
commit a711262e649c47f928443b66c2f7f467f0ab37d1
37 changes: 35 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,44 @@ func (b *builtinCastDecimalAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, resu
}

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

func (b *builtinCastDurationAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDuration, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalDuration(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
}
res, err := buf.GetDuration(i, b.tp.Decimal).ConvertToTime(stmtCtx, 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(stmtCtx, fsp)
if err != nil {
return err
}
times[i] = tm
}
return nil
}

func (b *builtinCastIntAsStringSig) 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 @@ -70,6 +70,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
&timeStrGener{},
&dataStrGener{},
}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDuration}},
},
}

Expand Down