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 compatibility bug with convert string to int return wrong result #7483

Merged
merged 8 commits into from
Aug 31, 2018

Conversation

CodeRushing
Copy link
Contributor

What problem does this PR solve?

fix the issue#7398

What is changed and how it works?

In types.floatStrToIntStr function, when extraZeroCount or intCnt overflows, just AppendWarning and return nil error

Check List

Tests

  • Unit test

@sre-bot
Copy link
Contributor

sre-bot commented Aug 24, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@CodeRushing
Copy link
Contributor Author

@XuHuaiyu @winoros squash the commits.

types/convert.go Outdated
@@ -275,7 +275,8 @@ func floatStrToIntStr(validFloat string) (string, error) {
}
if exp > 0 && int64(intCnt) > (math.MaxInt64-int64(exp)) {
// (exp + incCnt) overflows MaxInt64.
return validFloat, ErrOverflow.GenByArgs("BIGINT", validFloat)
sc.AppendError(ErrOverflow.GenByArgs("BIGINT", oriStr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the previous error message is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the error message in this case is like below

mysql> show warnings;
+---------+------+-------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '125e342.83' |
+---------+------+-------------------------------------------------+

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why AppendError? Shouldn't we AppendWarning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's should be AppendWarning. Already Fixed

types/convert.go Outdated
@@ -292,7 +293,8 @@ func floatStrToIntStr(validFloat string) (string, error) {
extraZeroCount := intCnt - len(digits)
if extraZeroCount > 20 {
// Return overflow to avoid allocating too much memory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeRushing Please update this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zz-jason already updated

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason added type/compatibility status/LGT1 Indicates that a PR has LGTM 1. contribution This PR is from a community contributor. component/expression labels Aug 27, 2018
@zz-jason
Copy link
Member

/run-all-tests

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@imtbkcat imtbkcat merged commit 40a4a2d into pingcap:master Aug 31, 2018
@CodeRushing CodeRushing deleted the my branch September 21, 2018 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants