-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
util/types:Handle out of range value when load data
#3508
Conversation
When insert an overflow string like "1343545435346432587475" to MySQL int type column, tidb will convert to max int64 instead of max int.
solve bug #3024 |
util/types/datum_test.go
Outdated
@@ -131,6 +133,15 @@ func testDatumToInt64(c *C, val interface{}, expect int64) { | |||
c.Assert(b, Equals, expect) | |||
} | |||
|
|||
func testDatumToInt64WithTargetType(c *C, val interface{}, tp byte, expectErr Checker, expectVal int64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add this test it in util/types/convert_test.go,
thus ToInt64WithTp
, testDatumToInt64WithTargetType
and testDatumToInt64WithTargetType
can be removed.
PTAL @zimulala |
@louishust Should we distinguish between loading data and insert statement? mysql> create table t (a int, b int not null); mysql> insert into t values (143, 1343545435346432587475); |
I think the sql_mode is modified at load data command internal in MySQL. |
I checked MySQL code and find the following code in sql/sql_yacc.yy:
So if load data with local keyword, the load will treat truncate error as warnings. And tidb only support load data local infile, so should always ignore the error,
The fillRowData's third parameter is true. |
@zimulala PTAL |
LGTM |
If using the statement of |
@zimulala Ignore the sql_mode, only LOCAL keyword matters. |
util/types/datum.go
Outdated
@@ -1327,6 +1327,8 @@ func (d *Datum) toSignedInteger(sc *variable.StatementContext, tp byte) (int64, | |||
case KindString, KindBytes: | |||
iVal, err := StrToInt(sc, d.GetString()) | |||
if err != nil { | |||
// adjust the overflow value | |||
iVal, _ = ConvertIntToInt(iVal, lowerBound, upperBound, tp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I forgot StrToInt
implementation details.
You can consider it like the logical.@louishust
@zimulala modified the logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
When insert an overflow string like "1343545435346432587475"
to MySQL int type column, tidb will convert to max int64
instead of max int.