From 4fa9906c5cac07e7b04bd3da886c3bbf4c11202f Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Thu, 22 Jun 2017 21:21:10 +0800 Subject: [PATCH 01/14] Rewrite built-in func makeDate using new expression evaluation architecture --- expression/builtin_time.go | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 4de45133a2153..b9f4f342715c8 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2023,35 +2023,35 @@ type makeDateFunctionClass struct { } func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { - sig := &builtinMakeDateSig{newBaseBuiltinFunc(args, ctx)} + tp := types.NewFieldType(mysql.TypeDate) + types.SetBinChsClnFlag(tp) + bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) + if err != nil { + return nil, errors.Trace(err) + } + sig := &builtinMakeDateSig{baseTimeBuiltinFunc{bf}} return sig.setSelf(sig), errors.Trace(c.verifyArgs(args)) } type builtinMakeDateSig struct { - baseBuiltinFunc + baseTimeBuiltinFunc } // eval evals a builtinMakeDateSig. // See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_makedate -func (b *builtinMakeDateSig) eval(row []types.Datum) (d types.Datum, err error) { - args, err := b.evalArgs(row) - if err != nil { - return d, errors.Trace(err) +func (b *builtinMakeDateSig) evalTime(row []types.Datum) (d types.Time, isNull bool, err error) { + args := b.getArgs() + var year, dayOfYear int64 + year, isNull, err = args[0].EvalInt(row, b.ctx.GetSessionVars().StmtCtx) + if isNull || err != nil { + return d, isNull, errors.Trace(err) } - if args[0].IsNull() || args[1].IsNull() { - return - } - sc := b.ctx.GetSessionVars().StmtCtx - year, err := args[0].ToInt64(sc) - if err != nil { - return d, errors.Trace(err) - } - dayOfYear, err := args[1].ToInt64(sc) - if err != nil { - return d, errors.Trace(err) + dayOfYear, isNull, err = args[1].EvalInt(row, b.ctx.GetSessionVars().StmtCtx) + if isNull || err != nil { + return d, isNull, errors.Trace(err) } if dayOfYear <= 0 || year < 0 || year > 9999 { - return + return d, true, nil } if year < 70 { year += 2000 @@ -2065,14 +2065,13 @@ func (b *builtinMakeDateSig) eval(row []types.Datum) (d types.Datum, err error) } retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - return d, errorOrWarning(types.ErrInvalidTimeFormat, b.ctx) + return d, true, errorOrWarning(types.ErrInvalidTimeFormat, b.ctx) } ret := types.TimeFromDays(retTimestamp + dayOfYear - 1) if ret.IsZero() || ret.Time.Year() > 9999 { - return + return d, true, nil } - d.SetMysqlTime(ret) - return + return ret, false, nil } type makeTimeFunctionClass struct { From 90c4e043224a0d70eb2b1d58c3f603dfaf821bc3 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Thu, 22 Jun 2017 22:13:42 +0800 Subject: [PATCH 02/14] executor:add test cases --- executor/executor_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/executor/executor_test.go b/executor/executor_test.go index 62dffaec044cc..09331a27ffd03 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -803,6 +803,22 @@ func (s *testSuite) TestStringBuiltin(c *C) { result.Check(testkit.Rows("")) } +func (s *testSuite) TestTimeBuiltin(c *C) { + defer func() { + s.cleanEnv(c) + testleak.AfterTest(c)() + }() + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + + // for makeDate + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b double, c datetime, d time, e char(20), f bit(10))") + tk.MustExec(`insert into t values(1, 1.1, "2017-01-01 12:01:01", "12:01:01", "abcdef", 0b10101)`) + result := tk.MustQuery("select makedate(a,a), makedate(b,b), makedate(c,c), makedate(d,d), makedate(e,e), makedate(f,f), makedate(null,null), makedate(a,b) from t") + result.Check(testkit.Rows("2001-01-01 2001-01-01 2021-01-21 2001-01-01")) +} + func (s *testSuite) TestBuiltin(c *C) { defer func() { s.cleanEnv(c) From b37fe84d3bf479f9b04c4c9b260af48b632f5027 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Thu, 22 Jun 2017 23:18:01 +0800 Subject: [PATCH 03/14] add test cases --- expression/builtin_time_test.go | 78 ++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 19abe14cbf077..212d8a8be2527 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -18,8 +18,11 @@ import ( "strings" "time" + "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" + "github.com/pingcap/tidb/mysql" + "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" @@ -1203,42 +1206,55 @@ func (s *testEvaluatorSuite) TestTimestamp(c *C) { func (s *testEvaluatorSuite) TestMakeDate(c *C) { defer testleak.AfterTest(c)() - tbl := []struct { - Args []interface{} - Want interface{} + cases := []struct { + args []interface{} + expected string + isNil bool + getErr bool }{ - {[]interface{}{71, 1}, "1971-01-01"}, - {[]interface{}{99, 1}, "1999-01-01"}, - {[]interface{}{100, 1}, "0100-01-01"}, - {[]interface{}{69, 1}, "2069-01-01"}, - {[]interface{}{70, 1}, "1970-01-01"}, - {[]interface{}{1000, 1}, "1000-01-01"}, - {[]interface{}{-1, 3660}, nil}, - {[]interface{}{10000, 3660}, nil}, - {[]interface{}{2060, 2900025}, "9999-12-31"}, - {[]interface{}{2060, 2900026}, nil}, - {[]interface{}{nil, 2900025}, nil}, - {[]interface{}{2060, nil}, nil}, - {[]interface{}{nil, nil}, nil}, - {[]interface{}{"71", 1}, "1971-01-01"}, - {[]interface{}{71, "1"}, "1971-01-01"}, - {[]interface{}{"71", "1"}, "1971-01-01"}, - } - Dtbl := tblToDtbl(tbl) - maketime := funcs[ast.MakeDate] - for idx, t := range Dtbl { - f, err := maketime.getFunction(datumsToConstants(t["Args"]), s.ctx) - c.Assert(err, IsNil) - got, err := f.eval(nil) - c.Assert(err, IsNil) - if t["Want"][0].Kind() == types.KindNull { - c.Assert(got.Kind(), Equals, types.KindNull, Commentf("[%v] - args:%v", idx, t["Args"])) + {[]interface{}{71, 1}, "1971-01-01", false, false}, + {[]interface{}{99, 1}, "1999-01-01", false, false}, + {[]interface{}{100, 1}, "0100-01-01", false, false}, + {[]interface{}{69, 1}, "2069-01-01", false, false}, + {[]interface{}{70, 1}, "1970-01-01", false, false}, + {[]interface{}{1000, 1}, "1000-01-01", false, false}, + {[]interface{}{-1, 3660}, "", true, false}, + {[]interface{}{10000, 3660}, "", true, false}, + {[]interface{}{2060, 2900025}, "9999-12-31", false, false}, + {[]interface{}{2060, 2900026}, "", true, false}, + {[]interface{}{nil, 2900025}, "", true, false}, + {[]interface{}{2060, nil}, "", true, false}, + {[]interface{}{"71", 1}, "1971-01-01", false, false}, + {[]interface{}{71, "1"}, "1971-01-01", false, false}, + {[]interface{}{"71", "1"}, "1971-01-01", false, false}, + {[]interface{}{nil, nil}, "", true, false}, + {[]interface{}{errors.New("must error"), errors.New("must error")}, "", false, true}, + } + + for _, t := range cases { + f, err := newFunctionForTest(s.ctx, ast.MakeDate, primitiveValsToConstants(t.args)...) + c.Assert(err, IsNil) + tp := f.GetType() + c.Assert(tp.Tp, Equals, mysql.TypeDate) + c.Assert(tp.Charset, Equals, charset.CharsetBin) + c.Assert(tp.Collate, Equals, charset.CollationBin) + c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) + d, err := f.Eval(nil) + if t.getErr { + c.Assert(err, NotNil) } else { - want, err := t["Want"][0].ToString() c.Assert(err, IsNil) - c.Assert(got.GetMysqlTime().String(), Equals, want, Commentf("[%v] - args:%v", idx, t["Args"])) + if t.isNil { + c.Assert(d.Kind(), Equals, types.KindNull) + } else { + c.Assert(d.GetMysqlTime().String(), Equals, t.expected) + } } } + + f, err := funcs[ast.Length].getFunction([]Expression{Zero}, s.ctx) + c.Assert(err, IsNil) + c.Assert(f.isDeterministic(), IsTrue) } func (s *testEvaluatorSuite) TestMakeTime(c *C) { From 20705593763509954dade46dfcc73586586428fe Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Thu, 22 Jun 2017 23:31:05 +0800 Subject: [PATCH 04/14] fix test cases ast error --- expression/builtin_time_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 212d8a8be2527..0aa9e3f6331a9 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1252,7 +1252,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { } } - f, err := funcs[ast.Length].getFunction([]Expression{Zero}, s.ctx) + f, err := funcs[ast.MakeDate].getFunction([]Expression{Zero}, s.ctx) c.Assert(err, IsNil) c.Assert(f.isDeterministic(), IsTrue) } From 94ba7104300556be0447579b6f8a7f6a899c23f0 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Thu, 22 Jun 2017 23:53:20 +0800 Subject: [PATCH 05/14] add flen,fix ci --- expression/builtin_time.go | 1 + expression/builtin_time_test.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index b9f4f342715c8..2cb2097ec298c 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2024,6 +2024,7 @@ type makeDateFunctionClass struct { func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { tp := types.NewFieldType(mysql.TypeDate) + tp.Flen = 10 types.SetBinChsClnFlag(tp) bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) if err != nil { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 0aa9e3f6331a9..45180a45f9c33 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1239,6 +1239,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { c.Assert(tp.Charset, Equals, charset.CharsetBin) c.Assert(tp.Collate, Equals, charset.CollationBin) c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) + c.Assert(tp.Flen, Equals, 10) d, err := f.Eval(nil) if t.getErr { c.Assert(err, NotNil) @@ -1252,7 +1253,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { } } - f, err := funcs[ast.MakeDate].getFunction([]Expression{Zero}, s.ctx) + f, err := funcs[ast.MakeDate].getFunction([]Expression{Zero, Zero}, s.ctx) c.Assert(err, IsNil) c.Assert(f.isDeterministic(), IsTrue) } From 828035cf9e10d678fb886d424a213e9cae481793 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 00:22:37 +0800 Subject: [PATCH 06/14] del flen --- expression/builtin_time.go | 3 +-- expression/builtin_time_test.go | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 2cb2097ec298c..cb3132cb5ce03 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2024,7 +2024,6 @@ type makeDateFunctionClass struct { func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { tp := types.NewFieldType(mysql.TypeDate) - tp.Flen = 10 types.SetBinChsClnFlag(tp) bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) if err != nil { @@ -2038,7 +2037,7 @@ type builtinMakeDateSig struct { baseTimeBuiltinFunc } -// eval evals a builtinMakeDateSig. +// evalTime evaluates a builtinMakeDateSig. // See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_makedate func (b *builtinMakeDateSig) evalTime(row []types.Datum) (d types.Time, isNull bool, err error) { args := b.getArgs() diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 45180a45f9c33..c5b023a728fd6 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1239,7 +1239,6 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { c.Assert(tp.Charset, Equals, charset.CharsetBin) c.Assert(tp.Collate, Equals, charset.CollationBin) c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) - c.Assert(tp.Flen, Equals, 10) d, err := f.Eval(nil) if t.getErr { c.Assert(err, NotNil) From 8078486bc2780896d7fd109b3e1c1d0d682d6541 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 10:02:54 +0800 Subject: [PATCH 07/14] Add flen MAX_DATE_WIDTH=10 --- expression/builtin_time.go | 1 + expression/builtin_time_test.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index cb3132cb5ce03..01be105f47c60 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2024,6 +2024,7 @@ type makeDateFunctionClass struct { func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { tp := types.NewFieldType(mysql.TypeDate) + tp.Flen = 10 types.SetBinChsClnFlag(tp) bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) if err != nil { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index c5b023a728fd6..8371744f3ba8c 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1222,11 +1222,11 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { {[]interface{}{10000, 3660}, "", true, false}, {[]interface{}{2060, 2900025}, "9999-12-31", false, false}, {[]interface{}{2060, 2900026}, "", true, false}, - {[]interface{}{nil, 2900025}, "", true, false}, - {[]interface{}{2060, nil}, "", true, false}, {[]interface{}{"71", 1}, "1971-01-01", false, false}, {[]interface{}{71, "1"}, "1971-01-01", false, false}, {[]interface{}{"71", "1"}, "1971-01-01", false, false}, + {[]interface{}{nil, 2900025}, "", true, false}, + {[]interface{}{2060, nil}, "", true, false}, {[]interface{}{nil, nil}, "", true, false}, {[]interface{}{errors.New("must error"), errors.New("must error")}, "", false, true}, } @@ -1239,6 +1239,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { c.Assert(tp.Charset, Equals, charset.CharsetBin) c.Assert(tp.Collate, Equals, charset.CollationBin) c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) + c.Assert(tp.Flen, Equals, 10) d, err := f.Eval(nil) if t.getErr { c.Assert(err, NotNil) From 45a0bcb08df08dbad56d81f4e9762302f724c432 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 10:37:53 +0800 Subject: [PATCH 08/14] define MAX_DATE_WIDTH as a constant in mysql/const.go as MySQL does --- expression/builtin_time.go | 2 +- expression/builtin_time_test.go | 2 +- mysql/const.go | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 01be105f47c60..a31ca981956a4 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2024,7 +2024,7 @@ type makeDateFunctionClass struct { func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { tp := types.NewFieldType(mysql.TypeDate) - tp.Flen = 10 + tp.Flen = mysql.MAX_DATE_WIDTH types.SetBinChsClnFlag(tp) bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) if err != nil { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 8371744f3ba8c..95f2e78f879c6 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1239,7 +1239,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { c.Assert(tp.Charset, Equals, charset.CharsetBin) c.Assert(tp.Collate, Equals, charset.CollationBin) c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) - c.Assert(tp.Flen, Equals, 10) + c.Assert(tp.Flen, Equals, mysql.MAX_DATE_WIDTH) d, err := f.Eval(nil) if t.getErr { c.Assert(err, NotNil) diff --git a/mysql/const.go b/mysql/const.go index 2a8bcc8c8984e..c15072b664377 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -193,6 +193,11 @@ const ( // AllPrivMask is the mask for PrivilegeType with all bits set to 1. const AllPrivMask = AllPriv - 1 +const ( + // YYYY-MM-DD + MAX_DATE_WIDTH = 10 +) + // Priv2UserCol is the privilege to mysql.user table column name. var Priv2UserCol = map[PrivilegeType]string{ CreatePriv: "Create_priv", From 08b4fafb2fd5f053c2c6cc6824f76464114e2168 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 10:49:56 +0800 Subject: [PATCH 09/14] fix ci --- expression/builtin_time.go | 2 +- expression/builtin_time_test.go | 2 +- mysql/const.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index a31ca981956a4..342e232d7c0d0 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2024,7 +2024,7 @@ type makeDateFunctionClass struct { func (c *makeDateFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { tp := types.NewFieldType(mysql.TypeDate) - tp.Flen = mysql.MAX_DATE_WIDTH + tp.Flen = mysql.MaxDateWidth types.SetBinChsClnFlag(tp) bf, err := newBaseBuiltinFuncWithTp(args, tp, ctx, tpInt, tpInt) if err != nil { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 95f2e78f879c6..b05f574007bc0 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1239,7 +1239,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { c.Assert(tp.Charset, Equals, charset.CharsetBin) c.Assert(tp.Collate, Equals, charset.CollationBin) c.Assert(tp.Flag, Equals, uint(mysql.BinaryFlag)) - c.Assert(tp.Flen, Equals, mysql.MAX_DATE_WIDTH) + c.Assert(tp.Flen, Equals, mysql.MaxDateWidth) d, err := f.Eval(nil) if t.getErr { c.Assert(err, NotNil) diff --git a/mysql/const.go b/mysql/const.go index c15072b664377..3a9c61823ac9a 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -195,7 +195,7 @@ const AllPrivMask = AllPriv - 1 const ( // YYYY-MM-DD - MAX_DATE_WIDTH = 10 + MaxDateWidth = 10 ) // Priv2UserCol is the privilege to mysql.user table column name. From 6e13eaf9e0d29294eeb9d2a631601055952d63a8 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 11:16:02 +0800 Subject: [PATCH 10/14] Standardize the code,add tests. --- expression/builtin_time.go | 5 +++-- expression/builtin_time_test.go | 1 + mysql/const.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 342e232d7c0d0..730f736653541 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2042,12 +2042,13 @@ type builtinMakeDateSig struct { // See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_makedate func (b *builtinMakeDateSig) evalTime(row []types.Datum) (d types.Time, isNull bool, err error) { args := b.getArgs() + sc := b.ctx.GetSessionVars().StmtCtx var year, dayOfYear int64 - year, isNull, err = args[0].EvalInt(row, b.ctx.GetSessionVars().StmtCtx) + year, isNull, err = args[0].EvalInt(row, sc) if isNull || err != nil { return d, isNull, errors.Trace(err) } - dayOfYear, isNull, err = args[1].EvalInt(row, b.ctx.GetSessionVars().StmtCtx) + dayOfYear, isNull, err = args[1].EvalInt(row, sc) if isNull || err != nil { return d, isNull, errors.Trace(err) } diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index b05f574007bc0..2a32ddca8addd 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1213,6 +1213,7 @@ func (s *testEvaluatorSuite) TestMakeDate(c *C) { getErr bool }{ {[]interface{}{71, 1}, "1971-01-01", false, false}, + {[]interface{}{71.1, 1.89}, "1971-01-02", false, false}, {[]interface{}{99, 1}, "1999-01-01", false, false}, {[]interface{}{100, 1}, "0100-01-01", false, false}, {[]interface{}{69, 1}, "2069-01-01", false, false}, diff --git a/mysql/const.go b/mysql/const.go index 3a9c61823ac9a..70ebc5159cec8 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -193,8 +193,9 @@ const ( // AllPrivMask is the mask for PrivilegeType with all bits set to 1. const AllPrivMask = AllPriv - 1 +// Built-in function field length. const ( - // YYYY-MM-DD + // MaxDateWidth YYYY-MM-DD MaxDateWidth = 10 ) From a41094f2a15b46f1f4674bbfa0be9dc07df8ff81 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 11:29:19 +0800 Subject: [PATCH 11/14] Modify the comment --- mysql/const.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql/const.go b/mysql/const.go index 70ebc5159cec8..034017754bb76 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -193,7 +193,7 @@ const ( // AllPrivMask is the mask for PrivilegeType with all bits set to 1. const AllPrivMask = AllPriv - 1 -// Built-in function field length. +// MYSQL type maximum length const ( // MaxDateWidth YYYY-MM-DD MaxDateWidth = 10 From f76fa884ce1fe7ebe07039709b09b0f6f4f02c32 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 13:02:43 +0800 Subject: [PATCH 12/14] Modify the comment. --- mysql/const.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql/const.go b/mysql/const.go index 034017754bb76..81d2f64ad7c65 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -193,9 +193,9 @@ const ( // AllPrivMask is the mask for PrivilegeType with all bits set to 1. const AllPrivMask = AllPriv - 1 -// MYSQL type maximum length +// MYSQL type maximum length. const ( - // MaxDateWidth YYYY-MM-DD + // MaxDateWidth YYYY-MM-DD. MaxDateWidth = 10 ) From 00b5d26b619346d6933b76c992118033b805df86 Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 14:15:32 +0800 Subject: [PATCH 13/14] s/MYSQL/MySQL --- mysql/const.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql/const.go b/mysql/const.go index 81d2f64ad7c65..37dba47d1cce0 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -193,7 +193,7 @@ const ( // AllPrivMask is the mask for PrivilegeType with all bits set to 1. const AllPrivMask = AllPriv - 1 -// MYSQL type maximum length. +// MySQL type maximum length. const ( // MaxDateWidth YYYY-MM-DD. MaxDateWidth = 10 From b82fb64a21af8ea9bfaa1a22d68581af3ed0e18c Mon Sep 17 00:00:00 2001 From: dawxy <97687341@qq.com> Date: Fri, 23 Jun 2017 14:42:02 +0800 Subject: [PATCH 14/14] return d, true is clearer --- expression/builtin_time.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 730f736653541..12366a0d10fcf 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2046,11 +2046,11 @@ func (b *builtinMakeDateSig) evalTime(row []types.Datum) (d types.Time, isNull b var year, dayOfYear int64 year, isNull, err = args[0].EvalInt(row, sc) if isNull || err != nil { - return d, isNull, errors.Trace(err) + return d, true, errors.Trace(err) } dayOfYear, isNull, err = args[1].EvalInt(row, sc) if isNull || err != nil { - return d, isNull, errors.Trace(err) + return d, true, errors.Trace(err) } if dayOfYear <= 0 || year < 0 || year > 9999 { return d, true, nil