From 9f7d6d23c093f0dc3abe4f6dcd5d7c514e3dd554 Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Mon, 11 Nov 2019 15:57:29 +0300 Subject: [PATCH] expression: implement vectorized evaluation for builtinFromUnixTime2ArgSig (#13319) --- expression/builtin_string_vec_test.go | 8 +++++ expression/builtin_time_vec.go | 45 +++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/expression/builtin_string_vec_test.go b/expression/builtin_string_vec_test.go index bd08d0ab9161c..4c5c965af6000 100644 --- a/expression/builtin_string_vec_test.go +++ b/expression/builtin_string_vec_test.go @@ -228,6 +228,14 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{ ast.Elt: { {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETInt, types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{&rangeInt64Gener{-1, 5}}}, }, + ast.FromUnixTime: { + {retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDecimal, types.ETString}, + geners: []dataGenerator{ + gener{defaultGener{eType: types.ETDecimal, nullRation: 0.9}}, + &constStrGener{"%y-%m-%d"}, + }, + }, + }, } func (s *testEvaluatorSuite) TestVectorizedBuiltinStringEvalOneVec(c *C) { diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 4a53c1b7ef7fe..bb59fe89651c5 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -128,11 +128,52 @@ func (b *builtinDateSig) vectorized() bool { } func (b *builtinFromUnixTime2ArgSig) vectorized() bool { - return false + return true } func (b *builtinFromUnixTime2ArgSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf1, err := b.bufAllocator.get(types.ETDecimal, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf1) + if err = b.args[0].VecEvalDecimal(b.ctx, input, buf1); err != nil { + return err + } + + buf2, err := b.bufAllocator.get(types.ETString, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf2) + if err = b.args[1].VecEvalString(b.ctx, input, buf2); err != nil { + return err + } + + result.ReserveString(n) + ds := buf1.Decimals() + fsp := int8(b.tp.Decimal) + for i := 0; i < n; i++ { + if buf1.IsNull(i) || buf2.IsNull(i) { + result.AppendNull() + continue + } + t, isNull, err := evalFromUnixTime(b.ctx, fsp, &ds[i]) + if err != nil { + return err + } + if isNull { + result.AppendNull() + continue + } + res, err := t.DateFormat(buf2.GetString(i)) + if err != nil { + return err + } + result.AppendString(res) + } + return nil } func (b *builtinSysDateWithoutFspSig) vectorized() bool {