-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
types: always handle overflow error outside the types package #47997
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #47997 +/- ##
================================================
+ Coverage 71.5845% 72.7674% +1.1829%
================================================
Files 1401 1424 +23
Lines 405930 412323 +6393
================================================
+ Hits 290583 300037 +9454
+ Misses 95533 93370 -2163
+ Partials 19814 18916 -898
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/retest |
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
Do we agree that the error handling in types
package should follow similar pattern? Which means the function in types
package should do its best-effort, and return valid values and all errors, the caller of these functions should take the responsibility to handle these errors.
Also, should we do the same refractoring for HandleTruncate
in the future?
The problem is that, some functions will return both TruncateError
and OverflowError
(in different cases), then we may need to provide a function to handle all possible errors 🤔, but I wonder whether it's too hard/complex to implement this function right considering all these situations. As MySQL itself is not clean, the attitude to warnings in different situations is different. For example, casting a json string to integer can have different warnings compared with casting a normal string to integer:
select cast('-1' as unsigned); -- has warning
select cast(cast('"-1"' as json) as unsigned); -- no warning
(Though, TiDB doesn't do well in warning compatibility now. Maybe it's not a big problem).
Yes, I agree with you. The best way is to remove all flags and force return the error. However, I'm not sure it is practice now because too many places rely on the error processing inside the
Maybe need serval functions to translate |
/retest |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: XuHuaiyu, YangKeao The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/retest |
What problem does this PR solve?
Issue Number: close #47517
All functions in
types
package should respect settingstypes.Context
. However, for most functions, it will ignoreoverflowAsWarning
settings and return this error directly. To make sure all methods follows the same behavior, we unified this behavior to always return overflow error and the overflow handle should be outside thetypes
packageWhat is changed and how it works?
HandleOverflow
intypes.ConvertJSONToInt
andtypes.ProduceDecWithSpecifiedTp
HandleOverflow
inbuiltinCastXXXAsDecimalSig.evalDecimal
andbuiltinCastJSONAsIntSig.evalInt
.FlagIgnoreOverflowError
,FlagZeroDateAsWarning
,FlagZeroInDateAsWarning
andFlagInvalidDateAsWarning
flags.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.