Skip to content

Commit

Permalink
expression: go generate vectorized addtime functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway committed Sep 23, 2019
1 parent ea963cb commit 73ec099
Show file tree
Hide file tree
Showing 9 changed files with 1,305 additions and 0 deletions.
1 change: 1 addition & 0 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

//go:generate go run generator/control_vec.go
//go:generate go run generator/time_vec.go

package expression

Expand Down
35 changes: 35 additions & 0 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,38 @@ func (b *builtinCastRealAsRealSig) vecEvalReal(input *chunk.Chunk, result *chunk
func (b *builtinCastRealAsRealSig) vectorized() bool {
return true
}

func (b *builtinCastTimeAsDurationSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
arg0, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(arg0)
if err := b.args[0].VecEvalTime(b.ctx, input, arg0); err != nil {
return err
}
arg0s := arg0.Times()
result.ResizeGoDuration(n, false)
result.MergeNulls(arg0)
ds := result.GoDurations()
for i, t := range arg0s {
if result.IsNull(i) {
continue
}
d, err := t.ConvertToDuration()
if err != nil {
return err
}
d, err = d.RoundFrac(int8(b.tp.Decimal))
if err != nil {
return err
}
ds[i] = d.Duration
}
return nil
}

func (b *builtinCastTimeAsDurationSig) vectorized() bool {
return true
}
20 changes: 20 additions & 0 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETInt}, geners: []dataGenerator{new(randDurInt)}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETDuration, childrenTypes: []types.EvalType{types.ETDatetime},
geners: []dataGenerator{&dateTimeGenerWithFsp{
defaultGener: defaultGener{nullRation: 0.2, eType: types.ETDatetime},
fsp: 1,
}},
},
},
}

type dateTimeGenerWithFsp struct {
defaultGener
fsp int8
}

func (g *dateTimeGenerWithFsp) gen() interface{} {
result := g.defaultGener.gen()
if t, ok := result.(types.Time); ok {
t.Fsp = g.fsp
return t
}
return result
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinCastEvalOneVec(c *C) {
testVectorizedEvalOneVec(c, vecBuiltinCastCases)
}
Expand Down
Loading

0 comments on commit 73ec099

Please sign in to comment.