Skip to content

Commit

Permalink
implement vectorized evaluation for builtinDayOfMonthSig (#12409)
Browse files Browse the repository at this point in the history
  • Loading branch information
luyunyyyyy authored and sre-bot committed Sep 26, 2019
1 parent e37464b commit 2dc6264
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
46 changes: 38 additions & 8 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,6 @@ func (b *builtinTimeToSecSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum
return errors.Errorf("not implemented")
}

func (b *builtinDayOfMonthSig) vectorized() bool {
return false
}

func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinStrToDateDatetimeSig) vectorized() bool {
return false
}
Expand Down Expand Up @@ -1243,3 +1235,41 @@ func (b *builtinTimestamp2ArgsSig) vecEvalTime(input *chunk.Chunk, result *chunk
func (b *builtinTimestamp2ArgsSig) vectorized() bool {
return true
}

func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}
result.ResizeInt64(n, false)
result.MergeNulls(buf)
i64s := result.Int64s()
ds := buf.Times()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if ds[i].IsZero() {
if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
i64s[i] = 0
continue
}
i64s[i] = int64(ds[i].Time.Day())
}
return nil
}

func (b *builtinDayOfMonthSig) vectorized() bool {
return true
}
4 changes: 3 additions & 1 deletion expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.Second: {},
ast.MicroSecond: {},
ast.Now: {},
ast.DayOfMonth: {},
ast.DayOfWeek: {},
ast.DayOfYear: {},
ast.Day: {},
Expand Down Expand Up @@ -78,6 +77,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.MonthName: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}},
},
ast.DayOfMonth: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinTimeEvalOneVec(c *C) {
Expand Down

0 comments on commit 2dc6264

Please sign in to comment.