Skip to content

Commit 826c299

Browse files
AndrewDiqw4990
authored andcommitted
handle unsigned hour overflow (#10074)
1 parent 7acbe52 commit 826c299

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

expression/builtin_time.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,6 +4682,10 @@ func (b *builtinMakeTimeSig) evalDuration(row chunk.Row) (types.Duration, bool,
46824682
var overflow bool
46834683
// MySQL TIME datatype: https://dev.mysql.com/doc/refman/5.7/en/time.html
46844684
// ranges from '-838:59:59.000000' to '838:59:59.000000'
4685+
if hour < 0 && mysql.HasUnsignedFlag(b.args[0].GetType().Flag) {
4686+
hour = 838
4687+
overflow = true
4688+
}
46854689
if hour < -838 {
46864690
hour = -838
46874691
overflow = true

expression/builtin_time_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,23 @@ func (s *testEvaluatorSuite) TestMakeTime(c *C) {
19391939
}
19401940
}
19411941

1942+
// MAKETIME(CAST(-1 AS UNSIGNED),0,0);
1943+
tp1 := &types.FieldType{
1944+
Tp: mysql.TypeLonglong,
1945+
Flag: mysql.UnsignedFlag,
1946+
Charset: charset.CharsetBin,
1947+
Collate: charset.CollationBin,
1948+
Flen: mysql.MaxIntWidth,
1949+
}
1950+
f := BuildCastFunction(s.ctx, &Constant{Value: types.NewDatum("-1"), RetType: types.NewFieldType(mysql.TypeString)}, tp1)
1951+
res, err := f.Eval(chunk.Row{})
1952+
c.Assert(err, IsNil)
1953+
f1, err := maketime.getFunction(s.ctx, s.datumsToConstants([]types.Datum{res, makeDatums(0)[0], makeDatums(0)[0]}))
1954+
c.Assert(err, IsNil)
1955+
got, err := evalBuiltinFunc(f1, chunk.Row{})
1956+
c.Assert(err, IsNil)
1957+
c.Assert(got.GetMysqlDuration().String(), Equals, "838:59:59")
1958+
19421959
tbl = []struct {
19431960
Args []interface{}
19441961
Want interface{}

0 commit comments

Comments
 (0)