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}}, }, }