Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix warning message when to meet strconv.ErrSyntax (#43358) #56032

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions sessionctx/stmtctx/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/pingcap/tidb/sessionctx/stmtctx",
visibility = ["//visibility:public"],
deps = [
"//errno",
"//parser",
"//parser/ast",
"//parser/model",
Expand Down
17 changes: 17 additions & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
Expand Down Expand Up @@ -880,6 +881,22 @@ func (sc *StatementContext) HandleTruncate(err error) error {
if err == nil {
return nil
}

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 {
return nil
}
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)
)
Loading