Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinNowWithArgSig (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin authored and XiaTianliang committed Dec 21, 2019
1 parent f84af94 commit 144fb87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 39 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,48 @@ func (b *builtinTimeTimeTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result
}

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

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

result.ResizeTime(n, false)
times := result.Times()
fsps := bufFsp.Int64s()

for i := 0; i < n; i++ {
fsp := int8(0)
if !bufFsp.IsNull(i) {
if fsps[i] > int64(types.MaxFsp) {
return errors.Errorf("Too-big precision %v specified for 'now'. Maximum is %v.", fsps[i], types.MaxFsp)
}
if fsps[i] < int64(types.MinFsp) {
return errors.Errorf("Invalid negative %d specified, must in [0, 6].", fsps[i])
}
fsp = int8(fsps[i])
}

t, isNull, err := evalNowWithFsp(b.ctx, fsp)
if err != nil {
return err
}
if isNull {
result.SetNull(i, true)
continue
}

times[i] = t
}
return nil
}

func (b *builtinSubDateStringRealSig) vectorized() bool {
Expand Down
3 changes: 3 additions & 0 deletions expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.MicroSecond: {},
ast.Now: {
{retEvalType: types.ETDatetime},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt},
geners: []dataGenerator{&rangeInt64Gener{0, 7}},
},
},
ast.DayOfWeek: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
Expand Down

0 comments on commit 144fb87

Please sign in to comment.