Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinMonthNameSig (
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored and sre-bot committed Sep 25, 2019
1 parent f53d63a commit 5986c6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
38 changes: 34 additions & 4 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,42 @@ func (b *builtinSubTimeStringNullSig) vecEvalString(input *chunk.Chunk, result *
return errors.Errorf("not implemented")
}

func (b *builtinMonthNameSig) vectorized() bool {
return false
func (b *builtinMonthNameSig) vecEvalString(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.ReserveString(n)
ds := buf.Times()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
mon := ds[i].Time.Month()
if (ds[i].IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil {
return err
}
result.AppendNull()
continue
} else if mon == 0 || ds[i].IsZero() {
result.AppendNull()
continue
}
result.AppendString(types.MonthNames[mon-1])
}
return nil
}

func (b *builtinMonthNameSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
func (b *builtinMonthNameSig) vectorized() bool {
return true
}

func (b *builtinSubDateDatetimeStringSig) 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 @@ -75,6 +75,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETString, types.ETString},
geners: []dataGenerator{nil, new(dataStrGener)}},
},
ast.MonthName: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}},
},
}

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

0 comments on commit 5986c6c

Please sign in to comment.