From 8bd484bf7fc0b714b2b5a94c777ee53dd4498928 Mon Sep 17 00:00:00 2001 From: tsthght <781181214@qq.com> Date: Wed, 9 Oct 2019 17:06:50 +0800 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinCastDurationAsStringSig' (#12541) --- expression/builtin_cast_vec.go | 37 +++++++++++++++++++++++++++-- expression/builtin_cast_vec_test.go | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index 546b878bc5..5c9483fe37 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -591,11 +591,44 @@ func (b *builtinCastDurationAsDurationSig) vecEvalDuration(input *chunk.Chunk, r } func (b *builtinCastDurationAsStringSig) vectorized() bool { - return false + return true } func (b *builtinCastDurationAsStringSig) vecEvalString(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 + } + + var res string + var isNull bool + sc := b.ctx.GetSessionVars().StmtCtx + result.ReserveString(n) + for i := 0; i < n; i++ { + if buf.IsNull(i) { + result.AppendNull() + continue + } + res, err = types.ProduceStrWithSpecifiedTp(buf.GetDuration(i, 0).String(), b.tp, sc, false) + if err != nil { + return err + } + res, isNull, err = padZeroForBinaryType(res, b.tp, b.ctx) + if err != nil { + return err + } + if isNull { + result.AppendNull() + continue + } + result.AppendString(res) + } + return nil } func (b *builtinCastDecimalAsRealSig) vectorized() bool { diff --git a/expression/builtin_cast_vec_test.go b/expression/builtin_cast_vec_test.go index 5c7a88990a..1c216583e4 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.ETDuration}}, {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}}, {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETTimestamp}}, {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETReal}},