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

expression: fix cast unsigned integer to decimal #7792

Merged
merged 2 commits into from
Sep 27, 2018

Conversation

CodeRushing
Copy link
Contributor

… integer range

What problem does this PR solve?

fix #7778

What is changed and how it works?

in evalDecimal function, it not only check the cast type unsigned flag, but also check the unsigned flag of arg

Check List

Tests

  • Unit test

@sre-bot
Copy link
Contributor

sre-bot commented Sep 27, 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.

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

fix lgtm
Really thanks!

f = BuildCastFunction(ctx, &Constant{Value: types.NewUintDatum(18446744073709551615), RetType: rt}, ft)
res, err = f.Eval(chunk.Row{})
c.Assert(err, IsNil)
u, err := res.GetMysqlDecimal().ToUint()
Copy link
Member

Choose a reason for hiding this comment

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

Here it's more likely checking cast(cast(arg as decimal) as unsigned).
Maybe ToString is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not like cast(cast(arg as decimal) as unsigned) , because when cast(arg as decimal) returns signed, res.GetMysqlDecimal().ToUint() will return range exceed error.

@winoros winoros added status/LGT1 Indicates that a PR has LGTM 1. contribution This PR is from a community contributor. type/bugfix This PR fixes a bug. component/expression labels Sep 27, 2018
@zz-jason zz-jason changed the title expression:fix cast unsigned to decimal bug when overflows the signed… expression: fix cast unsigned integer to decimal Sep 27, 2018
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
Copy link
Member

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. status/all tests passed and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 27, 2018
@zz-jason zz-jason merged commit bca8c27 into pingcap:master Sep 27, 2018
winoros added a commit to winoros/tidb that referenced this pull request Sep 27, 2018
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/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast(unsigned arg as decimal) doesn't work properly
4 participants