Skip to content

Commit

Permalink
*: filter particularly errors when truncateAsWarning is true (#40078)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Dec 21, 2022
1 parent fc3f04b commit 47ace08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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
16 changes: 16 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 @@ -865,6 +866,21 @@ 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) {
return err
}

if sc.IgnoreTruncate {
return nil
}
Expand Down
1 change: 1 addition & 0 deletions table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo, r
}

err = sc.HandleTruncate(err)
err = sc.HandleOverflow(err, err)

if forceIgnoreTruncate {
err = nil
Expand Down

0 comments on commit 47ace08

Please sign in to comment.