Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinFromUnixTime2A…
Browse files Browse the repository at this point in the history
…rgSig (#13319)
  • Loading branch information
ekalinin authored and sre-bot committed Nov 11, 2019
1 parent ceb31ef commit 9f7d6d2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 43 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9f7d6d2

Please sign in to comment.