Skip to content

Commit

Permalink
This is an automated cherry-pick of #43358
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
hawkingrei authored and ti-chi-bot committed Sep 12, 2024
1 parent 1097ba8 commit d9cf28f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,11 @@ error = '''
invalid year
'''

["types:8034"]
error = '''
Incorrect datetime value: '%s'
'''

["types:8037"]
error = '''
invalid week mode format: '%v'
Expand Down
4 changes: 4 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5515,6 +5515,10 @@ func TestStrToDateBuiltinWithWarnings(t *testing.T) {
tk.MustExec("use test")
tk.MustQuery(`SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d');`).Check(testkit.Rows("<nil>"))
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1411 Incorrect datetime value: '0000-1-01' for function str_to_date"))
tk.MustQuery("SELECT CAST('4#,8?Q' AS DATE);").Check(testkit.Rows("<nil>"))
tk.MustQuery(`show warnings;`).Check(testkit.Rows(
`Warning 8034 Incorrect datetime value: '4#,8?Q'`,
))
}

func TestReadPartitionedTable(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package expression

import (
"errors"
"math"
"strconv"
"strings"
Expand Down Expand Up @@ -1764,6 +1765,9 @@ func (b *builtinCastStringAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chu
}
tm, err := types.ParseTime(stmtCtx, buf.GetString(i), b.tp.GetType(), fsp, nil)
if err != nil {
if errors.Is(err, strconv.ErrSyntax) {
err = types.ErrIncorrectDatetimeValue.GenWithStackByArgs(buf.GetString(i))
}
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion expression/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
func handleInvalidTimeError(ctx sessionctx.Context, err error) error {
if err == nil || !(types.ErrWrongValue.Equal(err) || types.ErrWrongValueForType.Equal(err) ||
types.ErrTruncatedWrongVal.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) ||
types.ErrDatetimeFunctionOverflow.Equal(err)) {
types.ErrDatetimeFunctionOverflow.Equal(err) || types.ErrIncorrectDatetimeValue.Equal(err)) {
return err
}
sc := ctx.GetSessionVars().StmtCtx
Expand Down
20 changes: 20 additions & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,27 @@ func (sc *StatementContext) HandleTruncate(err error) error {
if err == nil {
return nil
}
<<<<<<< HEAD
if sc.IgnoreTruncate {
=======

err = errors.Cause(err)
if e, ok := err.(*errors.Error); !ok ||
(e.Code() != errno.ErrTruncatedWrongValue &&
e.Code() != errno.ErrDataTooLong &&
e.Code() != errno.ErrTruncatedWrongValueForField &&
e.Code() != errno.ErrWarnDataOutOfRange &&
e.Code() != errno.ErrDataOutOfRange &&
e.Code() != errno.ErrBadNumber &&
e.Code() != errno.ErrWrongValueForType &&
e.Code() != errno.ErrDatetimeFunctionOverflow &&
e.Code() != errno.WarnDataTruncated &&
e.Code() != errno.ErrIncorrectDatetimeValue) {
return err
}

if sc.IgnoreTruncate.Load() {
>>>>>>> 4f2ef40a0fe (*: fix warning message when to meet strconv.ErrSyntax (#43358))
return nil
}
if sc.TruncateAsWarning {
Expand Down
2 changes: 2 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ var (
// ErrPartitionColumnStatsMissing is returned when the partition-level column stats is missing and the build global-level stats fails.
// Put this error here is to prevent `import cycle not allowed`.
ErrPartitionColumnStatsMissing = dbterror.ClassTypes.NewStd(mysql.ErrPartitionColumnStatsMissing)
// ErrIncorrectDatetimeValue is returned when the input value is in wrong format for datetime.
ErrIncorrectDatetimeValue = dbterror.ClassTypes.NewStd(mysql.ErrIncorrectDatetimeValue)
)

0 comments on commit d9cf28f

Please sign in to comment.