Skip to content

Commit

Permalink
Rename to tidb_bound_staleness
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Apr 28, 2021
1 parent 096e355 commit c9309ba
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ var funcs = map[string]functionClass{
ast.YearWeek: &yearWeekFunctionClass{baseFunctionClass{ast.YearWeek, 1, 2}},
ast.LastDay: &lastDayFunctionClass{baseFunctionClass{ast.LastDay, 1, 1}},
// TSO functions
ast.ReadTSIn: &readTSInFunctionClass{baseFunctionClass{ast.ReadTSIn, 2, 2}},
ast.TiDBParseTso: &tidbParseTsoFunctionClass{baseFunctionClass{ast.TiDBParseTso, 1, 1}},
ast.TiDBBoundStaleness: &tidbBoundStalenessFunctionClass{baseFunctionClass{ast.TiDBBoundStaleness, 2, 2}},
ast.TiDBParseTso: &tidbParseTsoFunctionClass{baseFunctionClass{ast.TiDBParseTso, 1, 1}},

// string functions
ast.ASCII: &asciiFunctionClass{baseFunctionClass{ast.ASCII, 1, 1}},
Expand Down
14 changes: 7 additions & 7 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -7115,35 +7115,35 @@ func handleInvalidZeroTime(ctx sessionctx.Context, t types.Time) (bool, error) {
return true, handleInvalidTimeError(ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String()))
}

// readTSInFunctionClass reads a time window [a, b] and compares it with the latest resolvedTS
// tidbBoundStalenessFunctionClass reads a time window [a, b] and compares it with the latest resolvedTS
// to determine which TS to use in a read only transaction.
type readTSInFunctionClass struct {
type tidbBoundStalenessFunctionClass struct {
baseFunctionClass
}

func (c *readTSInFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) {
func (c *tidbBoundStalenessFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) {
if err := c.verifyArgs(args); err != nil {
return nil, err
}
bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETInt, types.ETDatetime, types.ETDatetime)
if err != nil {
return nil, err
}
sig := &builtinReadTSInSig{bf}
sig := &builtinTiDBBoundStalenessSig{bf}
return sig, nil
}

type builtinReadTSInSig struct {
type builtinTiDBBoundStalenessSig struct {
baseBuiltinFunc
}

func (b *builtinReadTSInSig) Clone() builtinFunc {
func (b *builtinTiDBBoundStalenessSig) Clone() builtinFunc {
newSig := &builtinTidbParseTsoSig{}
newSig.cloneFrom(&b.baseBuiltinFunc)
return newSig
}

func (b *builtinReadTSInSig) evalInt(row chunk.Row) (int64, bool, error) {
func (b *builtinTiDBBoundStalenessSig) evalInt(row chunk.Row) (int64, bool, error) {
leftTime, isNull, err := b.args[0].EvalTime(b.ctx, row)
if isNull || err != nil {
return 0, true, handleInvalidTimeError(b.ctx, err)
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ func (s *testEvaluatorSuite) TestTidbParseTso(c *C) {
}
}

func (s *testEvaluatorSuite) TestReadTSIn(c *C) {
func (s *testEvaluatorSuite) TestTiDBBoundStaleness(c *C) {
const timeParserLayout = "2006-01-02 15:04:05.000"
t1, err := time.Parse(timeParserLayout, "2015-09-21 09:53:04.877")
c.Assert(err, IsNil)
Expand Down Expand Up @@ -2928,7 +2928,7 @@ func (s *testEvaluatorSuite) TestReadTSIn(c *C) {
},
}

fc := funcs[ast.ReadTSIn]
fc := funcs[ast.TiDBBoundStaleness]
for _, test := range tests {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/expression/injectResolveTS",
fmt.Sprintf("return(%v)", test.injectResolveTS)), IsNil)
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ func (b *builtinTidbParseTsoSig) vecEvalTime(input *chunk.Chunk, result *chunk.C
return nil
}

func (b *builtinReadTSInSig) vectorized() bool {
func (b *builtinTiDBBoundStalenessSig) vectorized() bool {
return true
}

func (b *builtinReadTSInSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
func (b *builtinTiDBBoundStalenessSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf0, err := b.bufAllocator.get(types.ETDatetime, n)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ var vecBuiltinTimeCases = map[string][]vecExprBenchCase{
geners: []dataGenerator{newRangeInt64Gener(0, math.MaxInt64)},
},
},
ast.ReadTSIn: {
ast.TiDBBoundStaleness: {
{
retEvalType: types.ETInt,
childrenTypes: []types.EvalType{types.ETDatetime, types.ETDatetime},
Expand Down
20 changes: 10 additions & 10 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,24 +2263,24 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) {
result = tk.MustQuery(`select tidb_parse_tso(-1)`)
result.Check(testkit.Rows("<nil>"))

// for read_ts_in
// for tidb_bound_staleness
tk.MustExec("SET time_zone = '+00:00';")
t := time.Now().UTC()
ts := oracle.ComposeTS(t.Unix()*1000, 0)
readTSInTests := []struct {
tidbBoundStalenessTests := []struct {
sql string
injectResolveTS uint64
isNull bool
expect int64
}{
{
sql: `select read_ts_in(DATE_SUB(NOW(), INTERVAL 600 SECOND), DATE_ADD(NOW(), INTERVAL 600 SECOND))`,
sql: `select tidb_bound_staleness(DATE_SUB(NOW(), INTERVAL 600 SECOND), DATE_ADD(NOW(), INTERVAL 600 SECOND))`,
injectResolveTS: ts,
isNull: false,
expect: int64(ts),
},
{
sql: `select read_ts_in("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`,
sql: `select tidb_bound_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`,
injectResolveTS: func() uint64 {
phy, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 13:30:04.877")
c.Assert(err, IsNil)
Expand All @@ -2294,7 +2294,7 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) {
}(),
},
{
sql: `select read_ts_in("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`,
sql: `select tidb_bound_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`,
injectResolveTS: func() uint64 {
phy, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 11:30:04.877")
c.Assert(err, IsNil)
Expand All @@ -2308,33 +2308,33 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) {
}(),
},
{
sql: `select read_ts_in("2021-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`,
sql: `select tidb_bound_staleness("2021-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`,
injectResolveTS: 0,
isNull: true,
expect: 0,
},
// Time is too small.
{
sql: `select read_ts_in("0020-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`,
sql: `select tidb_bound_staleness("0020-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`,
injectResolveTS: 0,
isNull: true,
expect: 0,
},
// Wrong value.
{
sql: `select read_ts_in(1, 2)`,
sql: `select tidb_bound_staleness(1, 2)`,
injectResolveTS: 0,
isNull: true,
expect: 0,
},
{
sql: `select read_ts_in("invalid_time_1", "invalid_time_2")`,
sql: `select tidb_bound_staleness("invalid_time_1", "invalid_time_2")`,
injectResolveTS: 0,
isNull: true,
expect: 0,
},
}
for _, test := range readTSInTests {
for _, test := range tidbBoundStalenessTests {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/expression/injectResolveTS",
fmt.Sprintf("return(%v)", test.injectResolveTS)), IsNil)
result = tk.MustQuery(test.sql)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/pingcap/tidb

replace github.com/pingcap/parser v0.0.0-20210421190254-588138d35e55 => github.com/JmPotato/parser v0.0.0-20210427035105-f41eb27a4a0c
replace github.com/pingcap/parser v0.0.0-20210421190254-588138d35e55 => github.com/JmPotato/parser v0.0.0-20210428071746-2dcbd7ce4694

require (
github.com/BurntSushi/toml v0.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/HdrHistogram/hdrhistogram-go v0.9.0 h1:dpujRju0R4M/QZzcnR1LH1qm+TVG3U
github.com/HdrHistogram/hdrhistogram-go v0.9.0/go.mod h1:nxrse8/Tzg2tg3DZcZjm6qEclQKK70g0KxO61gFFZD4=
github.com/Jeffail/gabs/v2 v2.5.1 h1:ANfZYjpMlfTTKebycu4X1AgkVWumFVDYQl7JwOr4mDk=
github.com/Jeffail/gabs/v2 v2.5.1/go.mod h1:xCn81vdHKxFUuWWAaD5jCTQDNPBMh5pPs9IJ+NcziBI=
github.com/JmPotato/parser v0.0.0-20210427035105-f41eb27a4a0c h1:5+IaTm0Y02tgky2m5MVwzuNW4PKcxT+BeJq6EAHH6tQ=
github.com/JmPotato/parser v0.0.0-20210427035105-f41eb27a4a0c/go.mod h1:xZC8I7bug4GJ5KtHhgAikjTfU4kBv1Sbo3Pf1MZ6lVw=
github.com/JmPotato/parser v0.0.0-20210428071746-2dcbd7ce4694 h1:pBJc7xeGu1d7kTKl46Kfu5ZTOTpxsbi8Q7dwx7VmZWM=
github.com/JmPotato/parser v0.0.0-20210428071746-2dcbd7ce4694/go.mod h1:xZC8I7bug4GJ5KtHhgAikjTfU4kBv1Sbo3Pf1MZ6lVw=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down

0 comments on commit c9309ba

Please sign in to comment.