Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinCastDurationA…
Browse files Browse the repository at this point in the history
…sRealSig` (#13475)
  • Loading branch information
pingyu authored and qw4990 committed Nov 19, 2019
1 parent 045eb97 commit 7f02792
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,9 @@ func (b *builtinCastDurationAsRealSig) evalReal(row chunk.Row) (res float64, isN
if isNull || err != nil {
return res, isNull, err
}
if val.Fsp, err = types.CheckFsp(int(val.Fsp)); err != nil {
return res, false, err
}
res, err = val.ToNumber().ToFloat64()
return res, false, err
}
Expand Down
35 changes: 33 additions & 2 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,42 @@ func (b *builtinCastJSONAsStringSig) vecEvalString(input *chunk.Chunk, result *c
}

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

func (b *builtinCastDurationAsRealSig) vecEvalReal(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.ResizeFloat64(n, false)
result.MergeNulls(buf)
f64s := result.Float64s()

var duration types.Duration
fsp := int8(b.args[0].GetType().Decimal)
if fsp, err = types.CheckFsp(int(fsp)); err != nil {
return err
}
ds := buf.GoDurations()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}

duration.Duration = ds[i]
duration.Fsp = fsp
if f64s[i], err = duration.ToNumber().ToFloat64(); err != nil {
return err
}
}
return nil
}

func (b *builtinCastJSONAsIntSig) 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 @@ -39,6 +39,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDuration}, geners: []dataGenerator{&rangeDurationGener{nullRation: 0.5}}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDatetime},
geners: []dataGenerator{&dateTimeGenerWithFsp{
defaultGener: defaultGener{nullRation: 0.2, eType: types.ETDatetime},
Expand Down

0 comments on commit 7f02792

Please sign in to comment.