Skip to content

fix: align signed string casts with MySQL#25431

Open
ck89119 wants to merge 10 commits into
matrixorigin:mainfrom
ck89119:issue-25216-main
Open

fix: align signed string casts with MySQL#25431
ck89119 wants to merge 10 commits into
matrixorigin:mainfrom
ck89119:issue-25216-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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 as 7e0 failed 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:

  • make
  • go test ./pkg/sql/plan/function
  • go vet ./pkg/sql/plan/function
  • make static-check
  • mo-tester: func_cast 123/123, int 219/219, bigint 205/205, tinyint 241/241, smallint 210/210
  • Modified function coverage: leadingSignedInteger 100%, strToSigned 90.2%

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-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants