[SPARK-49204][SQL] Fix surrogate pair handling in StringReplace #47710
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 changes were proposed in this pull request?
Fix the following string expression to handle surrogate pairs properly:
The issue has to do with counting surrogate pairs, which are single Unicode code points (and single UTF-8 characters), but are represented using 2 characters in UTF-16 (Java String).
Example of incorrect result (under
UNICODEcollation, but similar issues are noted for all ICU collations):Why are the changes needed?
Currently, some string expressions are giving wrong results when working with surrogate pairs.
Does this PR introduce any user-facing change?
Yes, this expression will now work properly with surrogate pairs:
repeat.How was this patch tested?
New tests in
CollationSupportSuite.Was this patch authored or co-authored using generative AI tooling?
Yes.