Skip to content

Commit

Permalink
expression, types: fix unexpected result from TIME() when fsp digits …
Browse files Browse the repository at this point in the history
…> 6 (pingcap#21652)
  • Loading branch information
TszKitLo40 authored Dec 11, 2020
1 parent 5435f21 commit 579022c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,10 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) {
// result = tk.MustQuery("select time('2003-12-10-10 01:02:03.000123')")
// result.Check(testkit.Rows("00:20:03")

// Issue 20995
result = tk.MustQuery("select time('0.1234567')")
result.Check(testkit.Rows("00:00:00.123457"))

// for hour
result = tk.MustQuery(`SELECT hour("12:13:14.123456"), hour("12:13:14.000010"), hour("272:59:55"), hour(020005), hour(null), hour("27aaaa2:59:55");`)
result.Check(testkit.Rows("12 12 272 2 <nil> <nil>"))
Expand Down
4 changes: 3 additions & 1 deletion types/fsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func CheckFsp(fsp int) (int8, error) {
if fsp == int(UnspecifiedFsp) {
return DefaultFsp, nil
}
if fsp < int(MinFsp) || fsp > int(MaxFsp) {
if fsp < int(MinFsp) {
return DefaultFsp, errors.Errorf("Invalid fsp %d", fsp)
} else if fsp > int(MaxFsp) {
return MaxFsp, nil
}
return int8(fsp), nil
}
Expand Down
12 changes: 6 additions & 6 deletions types/fsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ func (s *FspTest) TestCheckFsp(c *C) {
c.Assert(err, IsNil)

obtained, err = CheckFsp(int(MaxFsp) + 1)
c.Assert(obtained, Equals, DefaultFsp)
c.Assert(err, ErrorMatches, "Invalid fsp "+strconv.Itoa(int(MaxFsp)+1))
c.Assert(obtained, Equals, MaxFsp)
c.Assert(err, IsNil)

obtained, err = CheckFsp(int(MaxFsp) + 2019)
c.Assert(obtained, Equals, DefaultFsp)
c.Assert(err, ErrorMatches, "Invalid fsp "+strconv.Itoa(int(MaxFsp)+2019))
c.Assert(obtained, Equals, MaxFsp)
c.Assert(err, IsNil)

obtained, err = CheckFsp(int(MaxFsp) + 4294967296)
c.Assert(obtained, Equals, DefaultFsp)
c.Assert(err, ErrorMatches, "Invalid fsp "+strconv.Itoa(int(MaxFsp)+4294967296))
c.Assert(obtained, Equals, MaxFsp)
c.Assert(err, IsNil)

obtained, err = CheckFsp(int(MaxFsp+MinFsp) / 2)
c.Assert(obtained, Equals, (MaxFsp+MinFsp)/2)
Expand Down
1 change: 0 additions & 1 deletion types/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ func (s *testTimeSuite) TestTimeFsp(c *C) {
Fsp int8
}{
{"00:00:00.1", -2},
{"00:00:00.1", 7},
}

for _, test := range errTable {
Expand Down

0 comments on commit 579022c

Please sign in to comment.