Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtin*TimeDiffSig (
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyj authored and sre-bot committed Nov 14, 2019
1 parent 2baaf1f commit 9a6d663
Show file tree
Hide file tree
Showing 7 changed files with 748 additions and 122 deletions.
81 changes: 65 additions & 16 deletions expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,36 +526,85 @@ func (g *randHexStrGener) gen() interface{} {
return string(buf)
}

// dataTimeStrGener is used to generate strings which are dataTime format
type dataTimeStrGener struct{}
// dateTimeGener is used to generate a dataTime
type dateTimeGener struct {
Fsp int
Year int
Month int
Day int
}

func (g *dateTimeGener) gen() interface{} {
if g.Year == 0 {
g.Year = 1970 + rand.Intn(100)
}
if g.Month == 0 {
g.Month = rand.Intn(10) + 1
}
if g.Day == 0 {
g.Day = rand.Intn(20) + 1
}
gt := types.FromDate(g.Year, g.Month, g.Day, rand.Intn(12), rand.Intn(60), rand.Intn(60), rand.Intn(1000000))
t := types.Time{Time: gt, Type: mysql.TypeDatetime}
return t
}

// dateTimeStrGener is used to generate strings which are dataTime format
type dateTimeStrGener struct {
Fsp int
Year int
Month int
Day int
}

func (g *dataTimeStrGener) gen() interface{} {
year := rand.Intn(2200)
month := rand.Intn(10) + 1
day := rand.Intn(20) + 1
func (g *dateTimeStrGener) gen() interface{} {
if g.Year == 0 {
g.Year = 1970 + rand.Intn(100)
}
if g.Month == 0 {
g.Month = rand.Intn(10) + 1
}
if g.Day == 0 {
g.Day = rand.Intn(20) + 1
}
hour := rand.Intn(12)
minute := rand.Intn(60)
second := rand.Intn(60)
dataTimeStr := fmt.Sprintf("%d-%d-%d %d:%d:%d",
g.Year, g.Month, g.Day, hour, minute, second)
if g.Fsp > 0 && g.Fsp <= 6 {
microFmt := fmt.Sprintf(".%%0%dd", g.Fsp)
return dataTimeStr + fmt.Sprintf(microFmt, rand.Int()%(10^g.Fsp))
}

return fmt.Sprintf("%d-%d-%d %d:%d:%d",
year, month, day, hour, minute, second)
return dataTimeStr
}

// timeStrGener is used to generate strings which are time format
type timeStrGener struct{}
type timeStrGener struct {
Year int
Month int
Day int
}

func (g *timeStrGener) gen() interface{} {
year := rand.Intn(2200)
month := rand.Intn(10) + 1
day := rand.Intn(20) + 1
if g.Year == 0 {
g.Year = 1970 + rand.Intn(100)
}
if g.Month == 0 {
g.Month = rand.Intn(10) + 1
}
if g.Day == 0 {
g.Day = rand.Intn(20) + 1
}

return fmt.Sprintf("%d-%d-%d", year, month, day)
return fmt.Sprintf("%d-%d-%d", g.Year, g.Month, g.Day)
}

// dataStrGener is used to generate strings which are data format
type dataStrGener struct{}
// dateStrGener is used to generate strings which are data format
type dateStrGener struct{}

func (g *dataStrGener) gen() interface{} {
func (g *dateStrGener) gen() interface{} {
hour := rand.Intn(12)
minute := rand.Intn(60)
second := rand.Intn(60)
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_cast_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ var vecBuiltinCastCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETString},
geners: []dataGenerator{
&dataTimeStrGener{},
&dateTimeStrGener{},
&timeStrGener{},
&dataStrGener{},
&dateStrGener{},
}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDuration}},
{retEvalType: types.ETDatetime, childrenTypes: []types.EvalType{types.ETDatetime}},
Expand Down
64 changes: 0 additions & 64 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,6 @@ func (b *builtinAddDateDatetimeDecimalSig) vecEvalTime(input *chunk.Chunk, resul
return errors.Errorf("not implemented")
}

func (b *builtinStringStringTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinStringStringTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinDayNameSig) vectorized() bool {
return true
}
Expand Down Expand Up @@ -554,14 +546,6 @@ func (b *builtinPeriodDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu
return nil
}

func (b *builtinTimeTimeTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinTimeTimeTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinNowWithArgSig) vectorized() bool {
return true
}
Expand Down Expand Up @@ -631,14 +615,6 @@ func (b *builtinSubDateDurationDecimalSig) vecEvalDuration(input *chunk.Chunk, r
return errors.Errorf("not implemented")
}

func (b *builtinNullTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinNullTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinGetFormatSig) vectorized() bool {
return true
}
Expand Down Expand Up @@ -820,14 +796,6 @@ func (b *builtinSubStringAndDurationSig) vecEvalString(input *chunk.Chunk, resul
return errors.Errorf("not implemented")
}

func (b *builtinTimeStringTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinTimeStringTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinFromDaysSig) vectorized() bool {
return true
}
Expand Down Expand Up @@ -872,14 +840,6 @@ func (b *builtinSubDatetimeAndStringSig) vecEvalTime(input *chunk.Chunk, result
return errors.Errorf("not implemented")
}

func (b *builtinDurationDurationTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinDurationDurationTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinSubDateStringStringSig) vectorized() bool {
return false
}
Expand Down Expand Up @@ -1089,14 +1049,6 @@ func (b *builtinNowWithoutArgSig) vecEvalTime(input *chunk.Chunk, result *chunk.
return nil
}

func (b *builtinStringDurationTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinStringDurationTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinTimestampLiteralSig) vectorized() bool {
return false
}
Expand Down Expand Up @@ -1712,14 +1664,6 @@ func (b *builtinAddDateStringStringSig) vecEvalTime(input *chunk.Chunk, result *
return errors.Errorf("not implemented")
}

func (b *builtinDurationStringTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinDurationStringTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinAddDateIntStringSig) vectorized() bool {
return false
}
Expand Down Expand Up @@ -1981,14 +1925,6 @@ func (b *builtinDateLiteralSig) vecEvalTime(input *chunk.Chunk, result *chunk.Co
return errors.Errorf("not implemented")
}

func (b *builtinStringTimeTimeDiffSig) vectorized() bool {
return false
}

func (b *builtinStringTimeTimeDiffSig) vecEvalDuration(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
}

func (b *builtinTimeLiteralSig) vectorized() bool {
return false
}
Expand Down
Loading

0 comments on commit 9a6d663

Please sign in to comment.