Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression:implement vectorized evaluation for builtinExtractDurationSig #13489

Merged
merged 15 commits into from
Dec 20, 2019
Merged
38 changes: 36 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,45 @@ func (b *builtinWeekWithModeSig) vecEvalInt(input *chunk.Chunk, result *chunk.Co
}

func (b *builtinExtractDurationSig) vectorized() bool {
return false
return true
}

func (b *builtinExtractDurationSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
unit, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(unit)
if err := b.args[0].VecEvalString(b.ctx, input, unit); err != nil {
return err
}
dur, err := b.bufAllocator.get(types.ETDuration, n)
if err != nil {
return err
}
defer b.bufAllocator.put(dur)
if err = b.args[1].VecEvalDuration(b.ctx, input, dur); err != nil {
return err
}
result.ResizeInt64(n, false)
result.MergeNulls(unit, dur)
i64s := result.Int64s()
durIs := dur.GoDurations()
var duration types.Duration
duration.Fsp = int8(b.args[1].GetType().Decimal)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
unitI := unit.GetString(i)
duration.Duration = durIs[i]
i64s[i], err = types.ExtractDurationNum(&duration, unitI)
if err != nil {
return err
}
}
return nil
}

func (b *builtinStrToDateDurationSig) vectorized() bool {
Expand Down
36 changes: 34 additions & 2 deletions expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
},
ast.Now: {
{retEvalType: types.ETDatetime},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt},
geners: []dataGenerator{&rangeInt64Gener{0, 7}},
{
retEvalType: types.ETDatetime,
childrenTypes: []types.EvalType{types.ETInt},
geners: []dataGenerator{&rangeInt64Gener{0, 7}},
},
},
ast.DayOfWeek: {
Expand Down Expand Up @@ -358,6 +360,36 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
},
ast.Extract: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDatetime}, geners: []dataGenerator{&dateTimeUnitStrGener{}, nil}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("MICROSECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("SECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("MINUTE"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("HOUR"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("SECOND_MICROSECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("MINUTE_MICROSECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("MINUTE_SECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("HOUR_MICROSECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("HOUR_SECOND"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{{Value: types.NewStringDatum("HOUR_MINUTE"), RetType: types.NewFieldType(mysql.TypeString)}},
},
},
}

Expand Down