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 builtinDayNameSig #12401

Merged
merged 34 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90c75c7
add builtinDayNameSig
b41sh Sep 25, 2019
0ee1ef4
merge
b41sh Sep 26, 2019
9cde7e1
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Sep 27, 2019
98b254a
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Sep 29, 2019
c23e6ba
refactor
b41sh Sep 30, 2019
f75b4f7
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Sep 30, 2019
92f930f
fix
b41sh Sep 30, 2019
63a435a
update test case
b41sh Sep 30, 2019
ee0a6b2
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Sep 30, 2019
713a1d5
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Oct 3, 2019
45430b4
update
b41sh Oct 7, 2019
f4818a3
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 8, 2019
21af6e5
Merge branch 'master' into vecexpr-builtinDayNameSig
qw4990 Oct 8, 2019
1096080
Merge branch 'vecexpr-builtinDayNameSig' of https://github.com/b41sh/…
b41sh Oct 9, 2019
663ff9a
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 9, 2019
6587c86
update
b41sh Oct 9, 2019
3dbbf3c
use callback func
b41sh Oct 9, 2019
5617a72
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 12, 2019
b5a6029
merge
b41sh Oct 14, 2019
7e12b4a
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 23, 2019
16d784c
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 27, 2019
55eaf2e
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Oct 29, 2019
9105876
dayname special case
b41sh Oct 30, 2019
653cbf1
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Oct 30, 2019
65f1c09
fix
b41sh Oct 31, 2019
d4d3a53
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Oct 31, 2019
490cb5c
remove dayname int real testcase
b41sh Nov 2, 2019
ced7a55
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Nov 2, 2019
c13830f
fix
b41sh Nov 2, 2019
352dc8e
Merge branch 'master' into vecexpr-builtinDayNameSig
b41sh Nov 2, 2019
1ff3920
Merge branch 'master' of https://github.com/pingcap/tidb into vecexpr…
b41sh Nov 6, 2019
cf05c71
fix retType err
b41sh Nov 6, 2019
b683d66
Merge branch 'master' into vecexpr-builtinDayNameSig
qw4990 Nov 11, 2019
30dd83e
Merge branch 'master' into vecexpr-builtinDayNameSig
qw4990 Nov 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package expression

import (
gotime "time"

"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -172,12 +174,111 @@ func (b *builtinStringStringTimeDiffSig) vecEvalDuration(input *chunk.Chunk, res
return errors.Errorf("not implemented")
}

// Monday is 0, ... Sunday = 6 in MySQL
// but in go, Sunday is 0, ... Saturday is 6
// we will do a conversion.
func weekdayConversion(weekday gotime.Weekday) int64 {
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
return (int64(weekday) + 6) % 7
}

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

// evalString evals a builtinDayNameSig.
// See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_dayname
func (b *builtinDayNameSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}

result.ReserveString(n)
ds := buf.Times()
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
continue
}
if ds[i].InvalidZero() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil {
return err
}
result.AppendNull()
continue
}
idx := weekdayConversion(ds[i].Time.Weekday())
result.AppendString(types.WeekdayNames[idx])
}
return nil
}

func (b *builtinDayNameSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}

result.ResizeFloat64(n, false)
result.MergeNulls(buf)
f64s := result.Float64s()
ds := buf.Times()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if ds[i].InvalidZero() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
f64s[i] = float64(weekdayConversion(ds[i].Time.Weekday()))
}

return nil
}

func (b *builtinDayNameSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalTime(b.ctx, input, buf); err != nil {
return err
}

result.ResizeInt64(n, false)
result.MergeNulls(buf)
i64s := result.Int64s()
ds := buf.Times()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
if ds[i].InvalidZero() {
if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil {
return err
}
result.SetNull(i, true)
continue
}
i64s[i] = weekdayConversion(ds[i].Time.Weekday())
}
return nil
}

func (b *builtinWeekDaySig) 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 @@ -97,6 +97,11 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
ast.DayOfMonth: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
},
ast.DayName: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETDatetime}},
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETDatetime}},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinTimeEvalOneVec(c *C) {
Expand Down