Skip to content

Commit 998cbf6

Browse files
AndrewDizz-jason
authored andcommitted
expression: handle maketime unsigned hour overflow(#10074) (#10089)
1 parent 9a2d2da commit 998cbf6

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
@@ -4603,6 +4603,10 @@ func (b *builtinMakeTimeSig) evalDuration(row chunk.Row) (types.Duration, bool,
46034603
var overflow bool
46044604
// MySQL TIME datatype: https://dev.mysql.com/doc/refman/5.7/en/time.html
46054605
// ranges from '-838:59:59.000000' to '838:59:59.000000'
4606+
if hour < 0 && mysql.HasUnsignedFlag(b.args[0].GetType().Flag) {
4607+
hour = 838
4608+
overflow = true
4609+
}
46064610
if hour < -838 {
46074611
hour = -838
46084612
overflow = true

expression/builtin_time_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,23 @@ func (s *testEvaluatorSuite) TestMakeTime(c *C) {
19151915
}
19161916
}
19171917

1918+
// MAKETIME(CAST(-1 AS UNSIGNED),0,0);
1919+
tp1 := &types.FieldType{
1920+
Tp: mysql.TypeLonglong,
1921+
Flag: mysql.UnsignedFlag,
1922+
Charset: charset.CharsetBin,
1923+
Collate: charset.CollationBin,
1924+
Flen: mysql.MaxIntWidth,
1925+
}
1926+
f := BuildCastFunction(s.ctx, &Constant{Value: types.NewDatum("-1"), RetType: types.NewFieldType(mysql.TypeString)}, tp1)
1927+
res, err := f.Eval(chunk.Row{})
1928+
c.Assert(err, IsNil)
1929+
f1, err := maketime.getFunction(s.ctx, s.datumsToConstants([]types.Datum{res, makeDatums(0)[0], makeDatums(0)[0]}))
1930+
c.Assert(err, IsNil)
1931+
got, err := evalBuiltinFunc(f1, chunk.Row{})
1932+
c.Assert(err, IsNil)
1933+
c.Assert(got.GetMysqlDuration().String(), Equals, "838:59:59")
1934+
19181935
tbl = []struct {
19191936
Args []interface{}
19201937
Want interface{}

0 commit comments

Comments
 (0)