diff --git a/expression/builtin_cast.go b/expression/builtin_cast.go index fb914f495b4f7..d3933f10a865c 100644 --- a/expression/builtin_cast.go +++ b/expression/builtin_cast.go @@ -552,7 +552,7 @@ func (b *builtinCastIntAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNul } res, err = types.ParseTimeFromNum(b.ctx.GetSessionVars().StmtCtx, val, b.tp.Tp, int8(b.tp.Decimal)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if b.tp.Tp == mysql.TypeDate { // Truncate hh:mm:ss part if the type is Date. @@ -841,7 +841,7 @@ func (b *builtinCastRealAsTimeSig) evalTime(row chunk.Row) (types.Time, bool, er sc := b.ctx.GetSessionVars().StmtCtx res, err := types.ParseTime(sc, fv, b.tp.Tp, int8(b.tp.Decimal)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if b.tp.Tp == mysql.TypeDate { // Truncate hh:mm:ss part if the type is Date. @@ -1007,7 +1007,7 @@ func (b *builtinCastDecimalAsTimeSig) evalTime(row chunk.Row) (res types.Time, i sc := b.ctx.GetSessionVars().StmtCtx res, err = types.ParseTimeFromFloatString(sc, string(val.ToString()), b.tp.Tp, int8(b.tp.Decimal)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if b.tp.Tp == mysql.TypeDate { // Truncate hh:mm:ss part if the type is Date. @@ -1223,7 +1223,7 @@ func (b *builtinCastStringAsTimeSig) evalTime(row chunk.Row) (res types.Time, is sc := b.ctx.GetSessionVars().StmtCtx res, err = types.ParseTime(sc, val, b.tp.Tp, int8(b.tp.Decimal)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if b.tp.Tp == mysql.TypeDate { // Truncate hh:mm:ss part if the type is Date. @@ -1277,7 +1277,7 @@ func (b *builtinCastTimeAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNu sc := b.ctx.GetSessionVars().StmtCtx if res, err = res.Convert(sc, b.tp.Tp); err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } res, err = res.RoundFrac(sc, int8(b.tp.Decimal)) if b.tp.Tp == mysql.TypeDate { @@ -1544,7 +1544,7 @@ func (b *builtinCastDurationAsTimeSig) evalTime(row chunk.Row) (res types.Time, sc := b.ctx.GetSessionVars().StmtCtx res, err = val.ConvertToTime(sc, b.tp.Tp) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } res, err = res.RoundFrac(sc, int8(b.tp.Decimal)) return res, false, err @@ -1668,7 +1668,7 @@ func (b *builtinCastJSONAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNu sc := b.ctx.GetSessionVars().StmtCtx res, err = types.ParseTime(sc, s, b.tp.Tp, int8(b.tp.Decimal)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if b.tp.Tp == mysql.TypeDate { // Truncate hh:mm:ss part if the type is Date. diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index dc1c73ee0665e..3f2880c7caebe 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -379,7 +379,7 @@ func (b *builtinCastIntAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk. } tm, err := types.ParseTimeFromNum(stmt, i64s[i], b.tp.Tp, fsp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -482,7 +482,7 @@ func (b *builtinCastJSONAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk } tm, err := types.ParseTime(stmtCtx, s, b.tp.Tp, fsp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -524,7 +524,7 @@ func (b *builtinCastRealAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk } tm, err := types.ParseTime(stmt, strconv.FormatFloat(f64s[i], 'f', -1, 64), b.tp.Tp, fsp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -601,7 +601,7 @@ func (b *builtinCastDurationAsTimeSig) vecEvalTime(input *chunk.Chunk, result *c duration.Fsp = fsp tm, err := duration.ConvertToTime(stmtCtx, b.tp.Tp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -1360,7 +1360,7 @@ func (b *builtinCastDecimalAsTimeSig) vecEvalTime(input *chunk.Chunk, result *ch } tm, err := types.ParseTimeFromFloatString(stmt, string(decimals[i].ToString()), b.tp.Tp, fsp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -1430,7 +1430,7 @@ func (b *builtinCastTimeAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk } res, err := times[i].Convert(stmt, b.tp.Tp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -1636,7 +1636,7 @@ func (b *builtinCastStringAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chu } tm, err := types.ParseTime(stmtCtx, buf.GetString(i), b.tp.Tp, fsp) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index a875630f277d6..da16b1941c781 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -600,7 +600,7 @@ func (b *builtinGreatestTimeSig) evalString(row chunk.Row) (_ string, isNull boo } t, err = types.ParseDatetime(sc, v) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return v, true, err } continue @@ -800,7 +800,7 @@ func (b *builtinLeastTimeSig) evalString(row chunk.Row) (res string, isNull bool } t, err = types.ParseDatetime(sc, v) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return v, true, err } else if !findInvalidTime { res = v diff --git a/expression/builtin_compare_vec.go b/expression/builtin_compare_vec.go index e6eec9128d136..5e08511a09fad 100644 --- a/expression/builtin_compare_vec.go +++ b/expression/builtin_compare_vec.go @@ -649,7 +649,7 @@ func (b *builtinGreatestTimeSig) vecEvalString(input *chunk.Chunk, result *chunk } argTime, err = types.ParseDatetime(sc, result.GetString(i)) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } continue @@ -739,7 +739,7 @@ func (b *builtinLeastTimeSig) vecEvalString(input *chunk.Chunk, result *chunk.Co } argTime, err = types.ParseDatetime(sc, result.GetString(i)) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } else if !findInvalidTime[i] { invalidValue[i] = result.GetString(i) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 8f2ee11bcb211..8b18dd995c159 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -289,11 +289,11 @@ func (b *builtinDateSig) Clone() builtinFunc { func (b *builtinDateSig) evalTime(row chunk.Row) (types.Time, bool, error) { expr, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } if expr.IsZero() { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, expr.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, expr.String())) } expr.SetCoreTime(types.FromDate(expr.Year(), expr.Month(), expr.Day(), 0, 0, 0, 0)) @@ -384,18 +384,18 @@ func (b *builtinDateDiffSig) Clone() builtinFunc { func (b *builtinDateDiffSig) evalInt(row chunk.Row) (int64, bool, error) { lhs, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } rhs, isNull, err := b.args[1].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) } if invalidRHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) } return 0, true, err } @@ -800,7 +800,7 @@ func (b *builtinDateFormatSig) Clone() builtinFunc { func (b *builtinDateFormatSig) evalString(row chunk.Row) (string, bool, error) { t, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return "", isNull, HandleInvalidTimeError(b.ctx, err) + return "", isNull, handleInvalidTimeError(b.ctx, err) } formatMask, isNull, err := b.args[1].EvalString(b.ctx, row) if isNull || err != nil { @@ -822,7 +822,7 @@ func (b *builtinDateFormatSig) evalString(row chunk.Row) (string, bool, error) { if isOriginalIntOrDecimalZero && !isOriginalStringZero { return "", true, nil } - return "", true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return "", true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } res, err := t.DateFormat(formatMask) @@ -1040,12 +1040,12 @@ func (b *builtinMonthSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return 0, false, nil } @@ -1083,11 +1083,11 @@ func (b *builtinMonthNameSig) Clone() builtinFunc { func (b *builtinMonthNameSig) evalString(row chunk.Row) (string, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return "", true, HandleInvalidTimeError(b.ctx, err) + return "", true, handleInvalidTimeError(b.ctx, err) } mon := arg.Month() if (arg.IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) { - return "", true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return "", true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } else if mon == 0 || arg.IsZero() { return "", true, nil } @@ -1126,7 +1126,7 @@ func (b *builtinDayNameSig) evalIndex(row chunk.Row) (int64, bool, error) { return 0, isNull, err } if arg.InvalidZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } // Monday is 0, ... Sunday = 6 in MySQL // but in go, Sunday is 0, ... Saturday is 6 @@ -1191,11 +1191,11 @@ func (b *builtinDayOfMonthSig) Clone() builtinFunc { func (b *builtinDayOfMonthSig) evalInt(row chunk.Row) (int64, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if arg.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return 0, false, nil } @@ -1232,10 +1232,10 @@ func (b *builtinDayOfWeekSig) Clone() builtinFunc { func (b *builtinDayOfWeekSig) evalInt(row chunk.Row) (int64, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if arg.InvalidZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } // 1 is Sunday, 2 is Monday, .... 7 is Saturday return int64(arg.Weekday() + 1), false, nil @@ -1271,10 +1271,10 @@ func (b *builtinDayOfYearSig) Clone() builtinFunc { func (b *builtinDayOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, isNull, HandleInvalidTimeError(b.ctx, err) + return 0, isNull, handleInvalidTimeError(b.ctx, err) } if arg.InvalidZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return int64(arg.YearDay()), false, nil @@ -1325,11 +1325,11 @@ func (b *builtinWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1357,11 +1357,11 @@ func (b *builtinWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, error) date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode := 0 @@ -1369,7 +1369,7 @@ func (b *builtinWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, error) if ok && modeStr != "" { mode, err = strconv.Atoi(modeStr) if err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrInvalidWeekModeFormat.GenWithStackByArgs(modeStr)) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrInvalidWeekModeFormat.GenWithStackByArgs(modeStr)) } } @@ -1408,11 +1408,11 @@ func (b *builtinWeekDaySig) Clone() builtinFunc { func (b *builtinWeekDaySig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return int64(date.Weekday()+6) % 7, false, nil @@ -1449,11 +1449,11 @@ func (b *builtinWeekOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } week := date.Week(3) @@ -1491,12 +1491,12 @@ func (b *builtinYearSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return 0, false, nil } @@ -1546,10 +1546,10 @@ func (b *builtinYearWeekWithModeSig) Clone() builtinFunc { func (b *builtinYearWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, isNull, HandleInvalidTimeError(b.ctx, err) + return 0, isNull, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1583,11 +1583,11 @@ func (b *builtinYearWeekWithoutModeSig) Clone() builtinFunc { func (b *builtinYearWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.InvalidZero() { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } year, week := date.YearWeek(0) @@ -1856,10 +1856,10 @@ func (b *builtinStrToDateDateSig) evalTime(row chunk.Row) (types.Time, bool, err sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.SetType(mysql.TypeDate) t.SetFsp(types.MinFsp) @@ -1889,10 +1889,10 @@ func (b *builtinStrToDateDatetimeSig) evalTime(row chunk.Row) (types.Time, bool, sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.SetType(mysql.TypeDatetime) t.SetFsp(int8(b.tp.Decimal)) @@ -1910,6 +1910,8 @@ func (b *builtinStrToDateDurationSig) Clone() builtinFunc { } // evalDuration +// TODO: If the NO_ZERO_DATE or NO_ZERO_IN_DATE SQL mode is enabled, zero dates or part of dates are disallowed. +// In that case, STR_TO_DATE() returns NULL and generates a warning. func (b *builtinStrToDateDurationSig) evalDuration(row chunk.Row) (types.Duration, bool, error) { date, isNull, err := b.args[0].EvalString(b.ctx, row) if isNull || err != nil { @@ -1923,13 +1925,10 @@ func (b *builtinStrToDateDurationSig) evalDuration(row chunk.Row) (types.Duratio sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Duration{}, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } - if b.ctx.GetSessionVars().SQLMode.HasNoZeroInDateMode() && t.InvalidZero() && !t.IsZero() { - return types.Duration{}, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) - } - if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && t == types.ZeroDatetime { - return types.Duration{}, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) + if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { + return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.SetFsp(int8(b.tp.Decimal)) dur, err := t.ConvertToDuration() @@ -2612,7 +2611,7 @@ func (du *baseDateArithmitical) getDateFromString(ctx sessionctx.Context, args [ sc := ctx.GetSessionVars().StmtCtx date, err := types.ParseTime(sc, dateStr, dateTp, types.MaxFsp) - return date, err != nil, HandleInvalidTimeError(ctx, err) + return date, err != nil, handleInvalidTimeError(ctx, err) } func (du *baseDateArithmitical) getDateFromInt(ctx sessionctx.Context, args []Expression, row chunk.Row, unit string) (types.Time, bool, error) { @@ -2624,7 +2623,7 @@ func (du *baseDateArithmitical) getDateFromInt(ctx sessionctx.Context, args []Ex sc := ctx.GetSessionVars().StmtCtx date, err := types.ParseTimeFromInt64(sc, dateInt) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(ctx, err) } dateTp := mysql.TypeDate @@ -2739,12 +2738,12 @@ func (du *baseDateArithmitical) getIntervalFromReal(ctx sessionctx.Context, args func (du *baseDateArithmitical) add(ctx sessionctx.Context, date types.Time, interval string, unit string) (types.Time, bool, error) { year, month, day, nano, err := types.ParseDurationValue(unit, interval) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } goTime, err := date.GoTime(time.Local) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } @@ -2758,16 +2757,16 @@ func (du *baseDateArithmitical) add(ctx sessionctx.Context, date types.Time, int } if goTime.Year() < 0 || goTime.Year() > 9999 { - return types.ZeroTime, true, HandleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) + return types.ZeroTime, true, handleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) } date.SetCoreTime(types.FromGoTime(goTime)) overflow, err := types.DateTimeIsOverflow(ctx.GetSessionVars().StmtCtx, date) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } if overflow { - return types.ZeroTime, true, HandleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) + return types.ZeroTime, true, handleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) } return date, false, nil } @@ -2775,7 +2774,7 @@ func (du *baseDateArithmitical) add(ctx sessionctx.Context, date types.Time, int func (du *baseDateArithmitical) addDuration(ctx sessionctx.Context, d types.Duration, interval string, unit string) (types.Duration, bool, error) { dur, err := types.ExtractDurationValue(unit, interval) if err != nil { - return types.ZeroDuration, true, HandleInvalidTimeError(ctx, err) + return types.ZeroDuration, true, handleInvalidTimeError(ctx, err) } retDur, err := d.Add(dur) if err != nil { @@ -2787,7 +2786,7 @@ func (du *baseDateArithmitical) addDuration(ctx sessionctx.Context, d types.Dura func (du *baseDateArithmitical) subDuration(ctx sessionctx.Context, d types.Duration, interval string, unit string) (types.Duration, bool, error) { dur, err := types.ExtractDurationValue(unit, interval) if err != nil { - return types.ZeroDuration, true, HandleInvalidTimeError(ctx, err) + return types.ZeroDuration, true, handleInvalidTimeError(ctx, err) } retDur, err := d.Sub(dur) if err != nil { @@ -2798,13 +2797,13 @@ func (du *baseDateArithmitical) subDuration(ctx sessionctx.Context, d types.Dura func (du *baseDateArithmitical) sub(ctx sessionctx.Context, date types.Time, interval string, unit string) (types.Time, bool, error) { year, month, day, nano, err := types.ParseDurationValue(unit, interval) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } year, month, day, nano = -year, -month, -day, -nano goTime, err := date.GoTime(time.Local) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } @@ -2819,16 +2818,16 @@ func (du *baseDateArithmitical) sub(ctx sessionctx.Context, date types.Time, int } if goTime.Year() < 0 || goTime.Year() > 9999 { - return types.ZeroTime, true, HandleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) + return types.ZeroTime, true, handleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) } date.SetCoreTime(types.FromGoTime(goTime)) overflow, err := types.DateTimeIsOverflow(ctx.GetSessionVars().StmtCtx, date) - if err := HandleInvalidTimeError(ctx, err); err != nil { + if err := handleInvalidTimeError(ctx, err); err != nil { return types.ZeroTime, true, err } if overflow { - return types.ZeroTime, true, HandleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) + return types.ZeroTime, true, handleInvalidTimeError(ctx, types.ErrDatetimeFunctionOverflow.GenWithStackByArgs("datetime")) } return date, false, nil } @@ -2857,7 +2856,7 @@ func (du *baseDateArithmitical) vecGetDateFromInt(b *baseBuiltinFunc, input *chu date, err := types.ParseTimeFromInt64(sc, i64s[i]) if err != nil { - err = HandleInvalidTimeError(b.ctx, err) + err = handleInvalidTimeError(b.ctx, err) if err != nil { return err } @@ -2904,7 +2903,7 @@ func (du *baseDateArithmitical) vecGetDateFromString(b *baseBuiltinFunc, input * date, err := types.ParseTime(sc, dateStr, dateTp, types.MaxFsp) if err != nil { - err = HandleInvalidTimeError(b.ctx, err) + err = handleInvalidTimeError(b.ctx, err) if err != nil { return err } @@ -4494,18 +4493,18 @@ func (b *builtinTimestampDiffSig) evalInt(row chunk.Row) (int64, bool, error) { } lhs, isNull, err := b.args[1].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, isNull, HandleInvalidTimeError(b.ctx, err) + return 0, isNull, handleInvalidTimeError(b.ctx, err) } rhs, isNull, err := b.args[2].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, isNull, HandleInvalidTimeError(b.ctx, err) + return 0, isNull, handleInvalidTimeError(b.ctx, err) } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) } if invalidRHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) } return 0, true, err } @@ -4785,7 +4784,7 @@ func (b *builtinTimestamp1ArgSig) evalTime(row chunk.Row) (types.Time, bool, err tm, err = types.ParseTime(sc, s, mysql.TypeDatetime, types.GetFsp(s)) } if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } return tm, false, nil } @@ -4817,7 +4816,7 @@ func (b *builtinTimestamp2ArgsSig) evalTime(row chunk.Row) (types.Time, bool, er tm, err = types.ParseTime(sc, arg0, mysql.TypeDatetime, types.GetFsp(arg0)) } if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } arg1, isNull, err := b.args[1].EvalString(b.ctx, row) if isNull || err != nil { @@ -4828,7 +4827,7 @@ func (b *builtinTimestamp2ArgsSig) evalTime(row chunk.Row) (types.Time, bool, er } duration, err := types.ParseDuration(sc, arg1, types.GetFsp(arg1)) if err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } tmp, err := tm.Add(sc, duration) if err != nil { @@ -5600,7 +5599,7 @@ func (b *builtinMakeDateSig) evalTime(row chunk.Row) (d types.Time, isNull bool, startTime := types.NewTime(types.FromDate(int(year), 1, 1, 0, 0, 0, 0), mysql.TypeDate, 0) retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - return d, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())) + return d, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())) } ret := types.TimeFromDays(retTimestamp + dayOfYear - 1) if ret.IsZero() || ret.Year() > 9999 { @@ -5664,10 +5663,10 @@ func (b *builtinMakeTimeSig) Clone() builtinFunc { func (b *builtinMakeTimeSig) getIntParam(arg Expression, row chunk.Row) (int64, bool, error) { if arg.GetType().EvalType() == types.ETReal { fRes, isNull, err := arg.EvalReal(b.ctx, row) - return int64(fRes), isNull, HandleInvalidTimeError(b.ctx, err) + return int64(fRes), isNull, handleInvalidTimeError(b.ctx, err) } iRes, isNull, err := arg.EvalInt(b.ctx, row) - return iRes, isNull, HandleInvalidTimeError(b.ctx, err) + return iRes, isNull, handleInvalidTimeError(b.ctx, err) } func (b *builtinMakeTimeSig) makeTime(hour int64, minute int64, second float64, hourUnsignedFlag bool) (types.Duration, error) { @@ -5893,7 +5892,7 @@ func (b *builtinQuarterSig) Clone() builtinFunc { func (b *builtinQuarterSig) evalInt(row chunk.Row) (int64, bool, error) { date, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { @@ -5906,7 +5905,7 @@ func (b *builtinQuarterSig) evalInt(row chunk.Row) (int64, bool, error) { if isOriginalIntOrDecimalZero && !isOriginalStringZero { return 0, false, nil } - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return int64((date.Month() + 2) / 3), false, nil @@ -6573,7 +6572,7 @@ func (b *builtinTimestampAddSig) evalString(row chunk.Row) (string, bool, error) } r := types.NewTime(types.FromGoTime(tb), b.resolveType(arg.Type(), unit), fsp) if err = r.Check(b.ctx.GetSessionVars().StmtCtx); err != nil { - return "", true, HandleInvalidTimeError(b.ctx, err) + return "", true, handleInvalidTimeError(b.ctx, err) } return r.String(), false, nil } @@ -6625,11 +6624,11 @@ func (b *builtinToDaysSig) evalInt(row chunk.Row) (int64, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } ret := types.TimestampDiff("DAY", types.ZeroDate, arg) if ret == 0 { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return ret, false, nil } @@ -6663,11 +6662,11 @@ func (b *builtinToSecondsSig) Clone() builtinFunc { func (b *builtinToSecondsSig) evalInt(row chunk.Row) (int64, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return 0, true, HandleInvalidTimeError(b.ctx, err) + return 0, true, handleInvalidTimeError(b.ctx, err) } ret := types.TimestampDiff("SECOND", types.ZeroDate, arg) if ret == 0 { - return 0, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return ret, false, nil } @@ -6803,12 +6802,12 @@ func (b *builtinLastDaySig) Clone() builtinFunc { func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { arg, isNull, err := b.args[0].EvalTime(b.ctx, row) if isNull || err != nil { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } tm := arg year, month := tm.Year(), tm.Month() if arg.InvalidZero() { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } lastDay := types.GetLastDay(year, month) ret := types.NewTime(types.FromDate(year, month, lastDay, 0, 0, 0, 0), mysql.TypeDate, types.DefaultFsp) @@ -6859,7 +6858,7 @@ func (b *builtinTidbParseTsoSig) Clone() builtinFunc { func (b *builtinTidbParseTsoSig) evalTime(row chunk.Row) (types.Time, bool, error) { arg, isNull, err := b.args[0].EvalInt(b.ctx, row) if isNull || err != nil || arg <= 0 { - return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err) + return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err) } t := oracle.GetTimeFromTS(uint64(arg)) diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 20ee9fbefba6d..976251cd0f075 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -50,7 +50,7 @@ func (b *builtinMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -89,7 +89,7 @@ func (b *builtinYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) er } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -117,7 +117,7 @@ func (b *builtinDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) e continue } if times[i].IsZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { return err } result.SetNull(i, true) @@ -266,7 +266,7 @@ func (b *builtinDayNameSig) vecEvalIndex(input *chunk.Chunk, apply func(i, res i continue } if ds[i].InvalidZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } applyNull(i) @@ -351,7 +351,7 @@ func (b *builtinWeekDaySig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) continue } if ds[i].IsZero() { - if err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -501,7 +501,7 @@ func (b *builtinYearWeekWithoutModeSig) vecEvalInt(input *chunk.Chunk, result *c } date := ds[i] if date.InvalidZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -697,7 +697,7 @@ func (b *builtinLastDaySig) vecEvalTime(input *chunk.Chunk, result *chunk.Column continue } if times[i].InvalidZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { return err } result.SetNull(i, true) @@ -746,14 +746,14 @@ func (b *builtinStrToDateDateSig) vecEvalTime(input *chunk.Chunk, result *chunk. var t types.Time succ := t.StrToDate(sc, bufStrings.GetString(i), bufFormats.GetString(i)) if !succ { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) continue } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) @@ -921,7 +921,7 @@ func (b *builtinQuarterSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) } date := ds[i] if date.IsZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -967,7 +967,7 @@ func (b *builtinWeekWithModeSig) vecEvalInt(input *chunk.Chunk, result *chunk.Co } date := ds[i] if date.IsZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -1062,14 +1062,14 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result var t types.Time succ := t.StrToDate(sc, bufStrings.GetString(i), bufFormats.GetString(i)) if !succ { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) continue } if hasNoZeroDateMode && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) @@ -1113,7 +1113,7 @@ func (b *builtinToSecondsSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum arg := ds[i] ret := types.TimestampDiff("SECOND", types.ZeroDate, arg) if ret == 0 { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { return err } result.SetNull(i, true) @@ -1261,7 +1261,7 @@ func (b *builtinMakeDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Colum startTime := types.NewTime(types.FromDate(int(years[i]), 1, 1, 0, 0, 0, 0), mysql.TypeDate, 0) retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - if err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())); err != nil { return err } result.SetNull(i, true) @@ -1300,7 +1300,7 @@ func (b *builtinWeekOfYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu continue } if ds[i].IsZero() { - if err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -1431,14 +1431,14 @@ func (b *builtinStrToDateDatetimeSig) vecEvalTime(input *chunk.Chunk, result *ch var t types.Time succ := t.StrToDate(sc, dateBuf.GetString(i), formatBuf.GetString(i)) if !succ { - if err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) continue } if hasNoZeroDateMode && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - if err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) @@ -1497,7 +1497,7 @@ func (b *builtinWeekWithoutModeSig) vecEvalInt(input *chunk.Chunk, result *chunk if ok && modeStr != "" { mode, err = strconv.Atoi(modeStr) if err != nil { - return HandleInvalidTimeError(b.ctx, types.ErrInvalidWeekModeFormat.GenWithStackByArgs(modeStr)) + return handleInvalidTimeError(b.ctx, types.ErrInvalidWeekModeFormat.GenWithStackByArgs(modeStr)) } } for i := 0; i < n; i++ { @@ -1506,7 +1506,7 @@ func (b *builtinWeekWithoutModeSig) vecEvalInt(input *chunk.Chunk, result *chunk } date := ds[i] if date.IsZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -1681,7 +1681,7 @@ func (b *builtinTimestampAddSig) vecEvalString(input *chunk.Chunk, result *chunk } r := types.NewTime(types.FromGoTime(tb), b.resolveType(arg.Type(), unit), fsp) if err = r.Check(b.ctx.GetSessionVars().StmtCtx); err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.AppendNull() @@ -1720,7 +1720,7 @@ func (b *builtinToDaysSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) arg := ds[i] ret := types.TimestampDiff("DAY", types.ZeroDate, arg) if ret == 0 { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { return err } result.SetNull(i, true) @@ -1786,7 +1786,7 @@ func (b *builtinDateFormatSig) vecEvalString(input *chunk.Chunk, result *chunk.C if isOriginalIntOrDecimalZero && !isOriginalStringZero { continue } - if errHandled := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); errHandled != nil { + if errHandled := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); errHandled != nil { return errHandled } continue @@ -1935,10 +1935,10 @@ func (b *builtinDateDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column } if invalidArg0, invalidArg1 := args0[i].InvalidZero(), args1[i].InvalidZero(); invalidArg0 || invalidArg1 { if invalidArg0 { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args0[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args0[i].String())) } if invalidArg1 { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args1[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args1[i].String())) } if err != nil { return err @@ -2066,7 +2066,7 @@ func (b *builtinDayOfYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum continue } if ds[i].InvalidZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -2147,7 +2147,7 @@ func (b *builtinYearWeekWithModeSig) vecEvalInt(input *chunk.Chunk, result *chun } date := ds[i] if date.IsZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -2210,10 +2210,10 @@ func (b *builtinTimestampDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.C } if invalidLHS, invalidRHS := lhs[i].InvalidZero(), rhs[i].InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs[i].String())) } if invalidRHS { - err = HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs[i].String())) } if err != nil { return err @@ -2407,7 +2407,7 @@ func (b *builtinMonthNameSig) vecEvalString(input *chunk.Chunk, result *chunk.Co } mon := ds[i].Month() if (ds[i].IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.AppendNull() @@ -2448,7 +2448,7 @@ func (b *builtinDayOfWeekSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum continue } if ds[i].InvalidZero() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -2593,7 +2593,7 @@ func (b *builtinTimestamp1ArgSig) vecEvalTime(input *chunk.Chunk, result *chunk. tm, err = types.ParseTime(sc, s, mysql.TypeDatetime, types.GetFsp(s)) } if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -2646,7 +2646,7 @@ func (b *builtinTimestamp2ArgsSig) vecEvalTime(input *chunk.Chunk, result *chunk tm, err = types.ParseTime(sc, arg0, mysql.TypeDatetime, types.GetFsp(arg0)) } if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -2660,7 +2660,7 @@ func (b *builtinTimestamp2ArgsSig) vecEvalTime(input *chunk.Chunk, result *chunk duration, err := types.ParseDuration(sc, arg1, types.GetFsp(arg1)) if err != nil { - if err = HandleInvalidTimeError(b.ctx, err); err != nil { + if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } result.SetNull(i, true) @@ -2699,7 +2699,7 @@ func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := HandleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) diff --git a/expression/errors.go b/expression/errors.go index c395fc5c18789..a88e374697298 100644 --- a/expression/errors.go +++ b/expression/errors.go @@ -50,8 +50,8 @@ var ( errSequenceAccessDenied = terror.ClassExpression.New(mysql.ErrTableaccessDenied, mysql.MySQLErrName[mysql.ErrTableaccessDenied]) ) -// HandleInvalidTimeError reports error or warning depend on the context. -func HandleInvalidTimeError(ctx sessionctx.Context, err error) error { +// handleInvalidTimeError reports error or warning depend on the context. +func handleInvalidTimeError(ctx sessionctx.Context, err error) error { if err == nil || !(types.ErrWrongValue.Equal(err) || types.ErrTruncatedWrongVal.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) || types.ErrDatetimeFunctionOverflow.Equal(err)) { diff --git a/expression/integration_test.go b/expression/integration_test.go index 1fb8a39b66ec6..8fec00e07273e 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -2185,24 +2185,6 @@ func (s *testIntegrationSuite) TestDatetimeOverflow(c *C) { tk.MustQuery(`select DATE_SUB('2008-11-23 22:47:31',INTERVAL -266076160 QUARTER);`).Check(testkit.Rows("")) } -func (s *testIntegrationSuite) TestNoZeroDate(c *C) { - defer s.cleanEnv(c) - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - - tk.MustExec("create table t (a date, b datetime)") - tk.MustExec("set sql_mode=''") - - tk.MustExec("insert into t values ('0000-00-00', '0000-00-00')") - tk.MustQuery("SELECT STR_TO_DATE('00/00/0000', '%m/%d/%Y');").Check(testkit.Rows("0000-00-00")) - - tk.MustExec("set sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES'") - tk.MustGetErrMsg("insert into t(a) values ('0000-00-00')", "[table:1366]Incorrect date value: '0000-00-00' for column 'a' at row 1") - tk.MustGetErrMsg("insert into t(b) values ('0000-00-00')", "[table:1366]Incorrect datetime value: '0000-00-00' for column 'b' at row 1") - - tk.MustQuery("SELECT STR_TO_DATE('00/00/0000', '%m/%d/%Y');").Check(testkit.Rows("")) -} - func (s *testIntegrationSuite2) TestBuiltin(c *C) { defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) diff --git a/table/column.go b/table/column.go index 1e83d9ccdec0e..5ddf268d0bd07 100644 --- a/table/column.go +++ b/table/column.go @@ -190,12 +190,6 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) ( truncateTrailingSpaces(&casted) } - if ((col.Tp == mysql.TypeDate && !casted.IsNull() && casted.GetMysqlTime() == types.ZeroDate) || (col.Tp == mysql.TypeDatetime && !casted.IsNull() && casted.GetMysqlTime() == types.ZeroDatetime)) && ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := expression.HandleInvalidTimeError(ctx, types.ErrWrongValue); err != nil { - return casted, err - } - } - if ctx.GetSessionVars().SkipUTF8Check { return casted, nil }