From 4155b3b80838221d327ce2e24eb21e5b77519a78 Mon Sep 17 00:00:00 2001 From: tsthght <781181214@qq.com> Date: Fri, 18 Oct 2019 15:59:19 +0800 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinCastTimeAsJSONSig' (#12795) --- expression/builtin_cast_vec.go | 28 ++++++++++++++++++++++++++-- expression/builtin_cast_vec_test.go | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index 4b8dbcfcfed21..ed14a1e6fb446 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -149,11 +149,35 @@ func (b *builtinCastRealAsRealSig) vectorized() bool { } func (b *builtinCastTimeAsJSONSig) vectorized() bool { - return false + return true } func (b *builtinCastTimeAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + 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.ReserveJSON(n) + tms := buf.Times() + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + + tp := tms[i].Type + if tp == mysql.TypeDatetime || tp == mysql.TypeTimestamp { + tms[i].Fsp = types.MaxFsp + } + result.AppendJSON(json.CreateBinary(tms[i].String())) + } + return nil } func (b *builtinCastRealAsStringSig) vectorized() bool { diff --git a/expression/builtin_cast_vec_test.go b/expression/builtin_cast_vec_test.go index 6496b1634c602..fce168c9fd9ef 100644 --- a/expression/builtin_cast_vec_test.go +++ b/expression/builtin_cast_vec_test.go @@ -50,6 +50,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{ {retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDuration}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETInt}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETReal}}, + {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDatetime}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDecimal}}, },