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 builtinTimestamp1ArgSig #12339

Merged
merged 11 commits into from
Sep 25, 2019
42 changes: 42 additions & 0 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,45 @@ func (b *builtinDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) e
func (b *builtinDateSig) vectorized() bool {
return true
}

func (b *builtinTimestamp1ArgSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}

result.ResizeTime(n, false)
result.MergeNulls(buf)
times := result.Times()
sc := b.ctx.GetSessionVars().StmtCtx
var tm types.Time
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
s := buf.GetString(i)
if b.isFloat {
tm, err = types.ParseTimeFromFloatString(sc, s, mysql.TypeDatetime, types.GetFsp(s))
} else {
tm, err = types.ParseTime(sc, s, mysql.TypeDatetime, types.GetFsp(s))
}

if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about add an error rate option in generator to cover this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update. PTAL @SunRunAway

}
times[i] = tm
}
return nil
}

func (b *builtinTimestamp1ArgSig) vectorized() bool {
return true
}
3 changes: 3 additions & 0 deletions expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.Date: {
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}},
},
ast.Timestamp: {
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETString}},
},
}

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