jiwen624 opened a new pull request, #57648:
URL: https://github.com/apache/spark/pull/57648

   ### What changes were proposed in this pull request?
   In `UTF8String.indexOf(pattern, start, occurrence)`, return not-found before 
negating `start` when it is `Int.MinValue`. `-Int.MinValue` overflows back to 
`Int.MinValue` (negative), so the backward-skip loop never ran and the 
out-of-range guard `charCount < charsToSkip` could not fire — the backward 
search then ran anchored at the end of the string. Such a start can never be in 
range, since string length is bounded by `Int.MaxValue`.
   
   
   ### Why are the changes needed?
   `instr` with `start = Int.MinValue` silently returns the position of the 
last match instead of 0 (not found):
   
   ```sql
   SELECT instr('abcabc', 'abc', -2147483648, 1);  -- returns 4, expected 0
   ```
   
   Every other out-of-range negative start correctly returns 0. Affects the 
UTF8_BINARY and UTF8_LCASE paths; ICU collations already return 0 for the same 
query, so this was also an internal inconsistency across collations.
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes - bug fix
   
   
   ### How was this patch tested?
   New test cases added
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to