fix: align signed string casts with MySQL#25431
Open
ck89119 wants to merge 10 commits into
Open
Conversation
strToFloat previously saturated overflow (±Inf) for all cast modes. In STRICT_TRANS_TABLES / castAssignment MySQL returns error 1264 (Out of range value) instead. Gate the saturation behind mode: assignment returns moerr.NewOutOfRangef, implicit/explicit still saturates to ±MaxFloat. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ParseFloat returns "value out of range" for both overflow (±Inf)
and underflow (~0). The previous check treated them identically,
rejecting underflow in strict mode. MySQL accepts underflow
silently (e.g. CAST('1e-400' AS DOUBLE) → 0, no warning).
Gate out-of-range rejection on math.IsInf(result, 0) so only true
overflow is rejected; underflow keeps its zero-rounded value.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #25216
What this PR does / why we need it:
String-to-SIGNED casts previously passed the entire input to
strconv.ParseInt, so values such as7e0failed instead of following MySQL's leading-integer conversion behavior.This change extracts the optional sign and leading decimal digits before parsing. It preserves the existing hexadecimal, binary, invalid-prefix, overflow, and UNSIGNED behavior. It also adds unit and BVT coverage for exponent-like and suffixed numeric strings, including implicit casts used by integer predicates.
Validation:
makego test ./pkg/sql/plan/functiongo vet ./pkg/sql/plan/functionmake static-checkmo-tester:func_cast123/123,int219/219,bigint205/205,tinyint241/241,smallint210/210leadingSignedInteger100%,strToSigned90.2%