Skip to content

Commit

Permalink
expression:implement vectorized evaluation for builtinExtractDuration…
Browse files Browse the repository at this point in the history
…Sig (pingcap#13489)
  • Loading branch information
icditwang authored and XiaTianliang committed Dec 21, 2019
1 parent 689c192 commit 2a1ea0f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
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

0 comments on commit 2a1ea0f

Please sign in to comment.