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
Next Next commit
expression:implement vectorized evaluation for builtinExtractDurationSig
  • Loading branch information
icditwang committed Nov 20, 2019
commit 8961f5ccce41a3c85fe2df1059500c7db7779922
2 changes: 2 additions & 0 deletions expression/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ type vecExprBenchCase struct {
// geners[gen1, gen2] will be regarded as geners[gen1, gen2, nil].
// This field is optional.
geners []dataGenerator
// constants are used to generate constant data for children[i].
constants []*Constant
}

type vecExprBenchCases map[string][]vecExprBenchCase
Expand Down
3 changes: 3 additions & 0 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2531,13 +2531,16 @@ func (c *extractFunctionClass) getFunction(ctx sessionctx.Context, args []Expres
"YEAR_MONTH": {},
}
isDatetimeUnit := true
fmt.Println("args0--", args[0].ConstItem())
args[0] = WrapWithCastAsString(ctx, args[0])
fmt.Println("args0--", args[0].ConstItem())
if _, isCon := args[0].(*Constant); isCon {
unit, _, err1 := args[0].EvalString(ctx, chunk.Row{})
if err1 != nil {
return nil, err1
}
_, isDatetimeUnit = datetimeUnits[unit]
fmt.Println("unit---", unit)
}
var bf baseBuiltinFunc
if isDatetimeUnit {
Expand Down
38 changes: 36 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,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
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
unitI := unit.GetString(i)
duration.Duration = durIs[i]
duration.Fsp = int8(types.UnspecifiedFsp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be b.args[1].GetType().Decimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that while I use gofmt command,the ast.Now's test case changed its style.Is it ok?

i64s[i], err = types.ExtractDurationNum(&duration, unitI)
if err != nil {
return err
}
}
return nil
}

func (b *builtinStrToDateDurationSig) vectorized() bool {
Expand Down
5 changes: 5 additions & 0 deletions expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
},
},
ast.MakeTime: {},
ast.Extract: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETDuration},
constants: []*Constant{&Constant{Value: types.NewStringDatum("test"), RetType: types.NewFieldType(mysql.TypeString)}, nil},
},
},
ast.PeriodAdd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{new(periodGener), new(periodGener)}},
},
Expand Down