Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinMakeDateSig (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 b123cda commit 14e98ce
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
63 changes: 61 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,11 +1063,70 @@ func (b *builtinAddDateIntDecimalSig) vecEvalTime(input *chunk.Chunk, result *ch
}

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

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

buf2, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf2)
if err := b.args[1].VecEvalInt(b.ctx, input, buf2); err != nil {
return err
}

result.ResizeTime(n, false)
result.MergeNulls(buf1, buf2)

times := result.Times()
years := buf1.Int64s()
days := buf2.Int64s()

for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if days[i] <= 0 || years[i] < 0 || years[i] > 9999 {
result.SetNull(i, true)
continue
}
if years[i] < 70 {
years[i] += 2000
} else if years[i] < 100 {
years[i] += 1900
}
startTime := types.Time{
Time: types.FromDate(int(years[i]), 1, 1, 0, 0, 0, 0),
Type: mysql.TypeDate,
Fsp: 0,
}
retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime)
if retTimestamp == 0 {
if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(startTime.String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
ret := types.TimeFromDays(retTimestamp + days[i] - 1)
if ret.IsZero() || ret.Time.Year() > 9999 {
result.SetNull(i, true)
continue
}
times[i] = ret
}
return nil
}

func (b *builtinWeekOfYearSig) vectorized() bool {
Expand Down
6 changes: 5 additions & 1 deletion expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.CurrentDate: {
{retEvalType: types.ETDatetime},
},
ast.MakeDate: {},
ast.MakeDate: {
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt, types.ETInt},
geners: []dataGenerator{&rangeInt64Gener{0, 2200}, &rangeInt64Gener{0, 365}},
},
},
ast.MakeTime: {},
ast.PeriodAdd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{new(periodGener), new(periodGener)}},
Expand Down

0 comments on commit 14e98ce

Please sign in to comment.