-
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
expression: fix cast string like '.1a1' to decimal has no warnings information #26005
base: master
Are you sure you want to change the base?
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/cc @wshwsh12 @lzmhhh123 |
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 agree on the original motivation to be compatible with MySQL. But the change set seems affect more than one behavior.
Would you mind to list the compatibility we'd like to keep preciously in the issue first? You can prepare your PR locally but we may figure out the problem first instead of rush into the code.
@@ -552,13 +552,14 @@ func (s *testColumnTypeChangeSuite) TestColumnTypeChangeFromStringToOthers(c *C) | |||
tk.MustExec("insert into t values ('123.45', '123.45', '123.45', '123.45', '123.45', '123.45', '123', '123')") | |||
tk.MustExec("alter table t modify c decimal(7, 4)") | |||
tk.MustExec("alter table t modify vc decimal(7, 4)") | |||
tk.MustExec("alter table t modify bny decimal(7, 4)") | |||
// alter binary 0x3132332E34350000 to decimal(7,4) will get error | |||
tk.MustGetErrCode("alter table t modify bny decimal(7, 4)", mysql.ErrTruncatedWrongValue) |
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.
We change existing test case here. Does it mean this PR changes TiDB behavior explicitly (more than a warning)?
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.
Yes, In MySQL, this case will directly return error
tk.MustExec("alter table t modify vbny decimal(7, 4)") | ||
tk.MustExec("alter table t modify bb decimal(7, 4)") | ||
tk.MustExec("alter table t modify txt decimal(7, 4)") | ||
tk.MustExec("alter table t modify e decimal(7, 4)") | ||
tk.MustExec("alter table t modify s decimal(7, 4)") | ||
tk.MustQuery("select * from t").Check(testkit.Rows("123.4500 123.4500 123.4500 123.4500 123.4500 123.4500 1.0000 1.0000")) | ||
tk.MustQuery("select * from t").Check(testkit.Rows("123.4500 123.4500 123.45\x00\x00 123.4500 123.4500 123.4500 1.0000 1.0000")) |
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.
ditto, it seems result changes.
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.
see the reason above
@@ -836,7 +836,7 @@ func (b *builtinCastRealAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, result | |||
if types.ErrOverflow.Equal(err) { | |||
warnErr := types.ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", b.args[0]) | |||
err = b.ctx.GetSessionVars().StmtCtx.HandleOverflow(err, warnErr) | |||
} else if types.ErrTruncated.Equal(err) { | |||
} else if strings.Contains(err.Error(), "Truncated incorrect") { |
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.
Why do we do string matching for identifying an error? It is quite brittle.
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.
Agree, sorry, i can't find more elegant methods to handle this, please do me a favor about this point
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.
- Can we use types.ErrTruncatedWrongVal.Equal(err)?
- Non-vec implement also need modify.
- Are you sure we need modify CastRealAsDecimal, instead of CastStringAsDecimal?
- Is there any related test? I didn't find the test cover the case.. Or maybe I ignore the test?
- May also need to modify the implementation in tikv....
@@ -244,10 +244,11 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) { | |||
c.Assert(terror.ErrorEqual(err, ErrOverflow), IsTrue, Commentf("err %v", err)) | |||
c.Assert(v.(*MyDecimal).String(), Equals, "-9999.9999") | |||
v, err = Convert("1,999.00", ft) | |||
c.Assert(terror.ErrorEqual(err, ErrBadNumber), IsTrue, Commentf("err %v", err)) | |||
c.Assert(terror.ErrorEqual(err, |
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.
ditto behavior changes
c.Assert(v.(*MyDecimal).String(), Equals, "1.0000") | ||
v, err = Convert("1,999,999.00", ft) | ||
c.Assert(terror.ErrorEqual(err, ErrBadNumber), IsTrue, Commentf("err %v", err)) | ||
c.Assert(terror.ErrorEqual(err, ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", "1,999,999.00")), IsTrue, Commentf("err %v", err)) |
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.
ditto behavior changes
if len(str) == 0 { | ||
*d = zeroMyDecimal | ||
return ErrBadNumber | ||
return ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", string(strBak)) |
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.
ditto behavior changes
@@ -549,6 +576,7 @@ func (d *MyDecimal) FromString(str []byte) error { | |||
if strErr != nil { | |||
return strErr | |||
} | |||
|
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.
please avoid unnecessary diff.
@@ -46,7 +46,8 @@ func init() { | |||
ast.NewDecimal = func(str string) (interface{}, error) { | |||
dec := new(types.MyDecimal) | |||
err := dec.FromString(hack.Slice(str)) | |||
if err == types.ErrTruncated { | |||
if err == types.ErrTruncated || (err != nil && |
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.
ditto brittle string matching.
Well I see the information in PR description. However, issue keeps the analyze and PR focuses on the implementation. Please update the information in issue and it'd be better to label with number so that we know how much cases we'd like to cover. Besides, I don't find a case matches the result of ALTER statement changes in the description. |
OK, i will make more description about this problem in the issue page
In Order to fix the problem , i change the stringToDecimal logic, which however affect the ALTER statements, for example |
@yuqi1129 Thanks for your update. I'll schedule another review tomorrow. |
@yuqi1129 I verify locally with MySQL 8.0.23 and behavior changes. I'd prefer discuss the expected behavior on the issue first. |
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 hesitated to approve this PR without enough background knowledge. Shall the other reviewers give significant suggestion.
ping @lzmhhh123 @wshwsh12 /cc @tangenta |
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.
Looks like the behavior is even stranger now.... Now this sql will return two warning messages.
[tidb]> select cast('1.4a' as decimal);
+-------------------------+
| cast('1.4a' as decimal) |
+-------------------------+
| 1 |
+-------------------------+
1 row in set, 2 warnings (0.001 sec)
[tidb]> show warnings;
+---------+------+-------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect DECIMAL value: '1.4a' |
| Warning | 1292 | Truncated incorrect DECIMAL value: '1.4' |
+---------+------+-------------------------------------------+
2 rows in set (0.000 sec)
In my opinion, we should not focus on fixing the inconsistency between these warning information and mysql at this stage, but other more serious problems (eg, returning wrong data).
@@ -836,7 +836,7 @@ func (b *builtinCastRealAsDecimalSig) vecEvalDecimal(input *chunk.Chunk, result | |||
if types.ErrOverflow.Equal(err) { | |||
warnErr := types.ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", b.args[0]) | |||
err = b.ctx.GetSessionVars().StmtCtx.HandleOverflow(err, warnErr) | |||
} else if types.ErrTruncated.Equal(err) { | |||
} else if strings.Contains(err.Error(), "Truncated incorrect") { |
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.
- Can we use types.ErrTruncatedWrongVal.Equal(err)?
- Non-vec implement also need modify.
- Are you sure we need modify CastRealAsDecimal, instead of CastStringAsDecimal?
- Is there any related test? I didn't find the test cover the case.. Or maybe I ignore the test?
- May also need to modify the implementation in tikv....
Just now, i am busy fix this, seems that in order to fix this, more code should be updated and change.
You are right, much attention has been put to this minor problem and the output is not of much importance. we can ignore warning info inconsistence currently and focus on more meaningful problem. i will close the PR and submit it in the future. thanks for your kindly advice. |
@yuqi1129: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What problem does this PR solve?
Issue Number: close #26004
Problem Summary:
also fix problem like
warning information is
1.4
not1.4a
warning info is inconsistent with MySQL
Warning info is somewhat Semi-finished products
The above SQL should have warning information
What is changed and how it works?
Proposal: xxx
What's Changed:
How it Works:
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note
No release note
.