From ebaa8a720438f6bc92514a08c9403574a62ccde1 Mon Sep 17 00:00:00 2001 From: tsthght <781181214@qq.com> Date: Tue, 8 Oct 2019 16:34:41 +0800 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinCastJSONAsStringSig' (#12542) --- expression/builtin_cast_vec.go | 22 ++++++++++++++++++++-- expression/builtin_cast_vec_test.go | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index dce203af79..3999295db3 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -456,11 +456,29 @@ func (b *builtinCastJSONAsJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk } func (b *builtinCastJSONAsStringSig) vectorized() bool { - return false + return true } func (b *builtinCastJSONAsStringSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETJson, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[0].VecEvalJSON(b.ctx, input, buf); err != nil { + return err + } + + result.ReserveString(n) + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + result.AppendString(buf.GetJSON(i).String()) + } + return nil } func (b *builtinCastDurationAsRealSig) vectorized() bool { diff --git a/expression/builtin_cast_vec_test.go b/expression/builtin_cast_vec_test.go index db21c6f55e..2ea368f913 100644 --- a/expression/builtin_cast_vec_test.go +++ b/expression/builtin_cast_vec_test.go @@ -37,6 +37,7 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{ }, {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt}}, {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDatetime}}, + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETJson}}, {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDecimal}}, }, }