From dc636afa04f790bb00382947ff5c6541596a5d4e Mon Sep 17 00:00:00 2001 From: tsthght <781181214@qq.com> Date: Thu, 31 Oct 2019 19:17:16 +0800 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinCastDurationAsJSONSig' (#12797) --- expression/builtin_cast_vec.go | 26 ++++++++++++++++++++++++-- expression/builtin_cast_vec_test.go | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index f7157051bc57e..3228803c3c911 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -1209,9 +1209,31 @@ func (b *builtinCastDecimalAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *ch } func (b *builtinCastDurationAsJSONSig) vectorized() bool { - return false + return true } func (b *builtinCastDurationAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETDuration, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err = b.args[0].VecEvalDuration(b.ctx, input, buf); err != nil { + return err + } + + result.ReserveJSON(n) + var dur types.Duration + dur.Fsp = types.MaxFsp + ds := buf.GoDurations() + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + dur.Duration = ds[i] + result.AppendJSON(json.CreateBinary(dur.String())) + } + return nil } diff --git a/expression/builtin_cast_vec_test.go b/expression/builtin_cast_vec_test.go index 3c18896076953..12eb48479254a 100644 --- a/expression/builtin_cast_vec_test.go +++ b/expression/builtin_cast_vec_test.go @@ -51,6 +51,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.ETDuration}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETDatetime}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson}}, {retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&jsonStringGener{}}},