From d5e652ec1c35f2236dd2ede27adcab82f7e4edc1 Mon Sep 17 00:00:00 2001 From: AndrewDi Date: Tue, 9 Apr 2019 21:57:00 +0800 Subject: [PATCH] handle unsigned hour overflow --- expression/builtin_time.go | 4 ++++ expression/builtin_time_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index b22bab3d427da..dc586cffc19fe 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -4603,6 +4603,10 @@ func (b *builtinMakeTimeSig) evalDuration(row chunk.Row) (types.Duration, bool, var overflow bool // MySQL TIME datatype: https://dev.mysql.com/doc/refman/5.7/en/time.html // ranges from '-838:59:59.000000' to '838:59:59.000000' + if hour < 0 && mysql.HasUnsignedFlag(b.args[0].GetType().Flag) { + hour = 838 + overflow = true + } if hour < -838 { hour = -838 overflow = true diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 436d0a87289b2..e52ddf09c44cb 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1915,6 +1915,23 @@ func (s *testEvaluatorSuite) TestMakeTime(c *C) { } } + // MAKETIME(CAST(-1 AS UNSIGNED),0,0); + tp1 := &types.FieldType{ + Tp: mysql.TypeLonglong, + Flag: mysql.UnsignedFlag, + Charset: charset.CharsetBin, + Collate: charset.CollationBin, + Flen: mysql.MaxIntWidth, + } + f := BuildCastFunction(s.ctx, &Constant{Value: types.NewDatum("-1"), RetType: types.NewFieldType(mysql.TypeString)}, tp1) + res, err := f.Eval(chunk.Row{}) + c.Assert(err, IsNil) + f1, err := maketime.getFunction(s.ctx, s.datumsToConstants([]types.Datum{res, makeDatums(0)[0], makeDatums(0)[0]})) + c.Assert(err, IsNil) + got, err := evalBuiltinFunc(f1, chunk.Row{}) + c.Assert(err, IsNil) + c.Assert(got.GetMysqlDuration().String(), Equals, "838:59:59") + tbl = []struct { Args []interface{} Want interface{}