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 builtinLastDaySig #13503

Merged
merged 9 commits into from
Nov 20, 2019
4 changes: 2 additions & 2 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6532,8 +6532,8 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) {
return types.Time{}, true, handleInvalidTimeError(b.ctx, err)
}
tm := arg.Time
year, month, day := tm.Year(), tm.Month(), tm.Day()
if month == 0 || day == 0 {
year, month := tm.Year(), tm.Month()
if arg.InvalidZero() {
return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))
}
lastDay := types.GetLastDay(year, month)
Expand Down
29 changes: 27 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,36 @@ func (b *builtinGetFormatSig) getFormat(format, location string) string {
}

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

func (b *builtinLastDaySig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
if err := b.args[0].VecEvalTime(b.ctx, input, result); err != nil {
return err
}
times := result.Times()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if times[i].InvalidZero() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(times[i].String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
tm := times[i].Time
year, month := tm.Year(), tm.Month()
SunRunAway marked this conversation as resolved.
Show resolved Hide resolved
lastDay := types.GetLastDay(year, month)
times[i] = types.Time{
Time: types.FromDate(year, month, lastDay, 0, 0, 0, 0),
Type: mysql.TypeDate,
Fsp: types.DefaultFsp,
}
}
return nil
}

func (b *builtinAddDateStringDecimalSig) 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 @@ -259,6 +259,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
// {retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt},
// geners: []dataGenerator{&rangeInt64Gener{begin: 0, end: 7}}},
},
ast.LastDay: {
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}},
},
}

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