[FLINK-40578][table-runtime] OVERLAY discards the rest of the string and splits supplementary-plane characters - #29123
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
…g and splits supplementary-plane characters Generated-by: Claude Code (Opus 5)
Collaborator
davidradl
reviewed
Sep 10, 2026
| ("abcdef".overlay("X", 1, 0), "OVERLAY('abcdef' PLACING 'X' FROM 1 FOR 0)", "Xabcdef"), | ||
| ("abcdef".overlay("X", 6, 0), "OVERLAY('abcdef' PLACING 'X' FROM 6 FOR 0)", "abcdeXf"), | ||
|
|
||
| // a supplementary-plane character is one character and is never split into half a pair |
Contributor
There was a problem hiding this comment.
potential additional test cases
- for malformed/unpaired surrogates
- verifying behaviour on pure surrogate strings
wdyt?
Contributor
Author
There was a problem hiding this comment.
A SQL literal can't hold an unpaired surrogate, it becomes ? before execution: CHAR_LENGTH('a\ud83db') returns 3 and the value is a?b. Cases written that way would test 'a?b'.
The function handles them: a lone surrogate counts as one code point, overlay("a\ud83db", "X", 1, 1) gives X\ud83db. Only a direct unit test reaches that, and there's no SqlFunctionUtils test class today. Add one?
Contributor
There was a problem hiding this comment.
I think you are addressing point 1. If you think it is worth adding a test - please add.
What are your thoughts on point 2?
Contributor
Author
|
@flinkbot run azure |
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 is the purpose of the change
OVERLAYreturns wrong results for several argument combinations. The first row needs no unusual data:OVERLAY('abcdef' PLACING 'X' FROM 2 FOR 0)aXaXbcdefOVERLAY('a😀b' PLACING 'X' FROM 2 FOR 1)aX+ unpaired surrogate +baXbOVERLAY('abc' PLACING '😀' FROM 2)a😀a😀cOVERLAY('123456789' PLACING 'abc' FROM 2 FOR 2147483647)StringIndexOutOfBoundsException1abcIn
SqlFunctionUtils#overlay: alen > 0guard drops the tail when the replaced length is zero,offsets count UTF-16 code units rather than characters, and
int len = (int) lengthwraps.Brief change log
BinaryStringData#substringalready uses forSUBSTRING.lengthstays along, so a largeFORneither wraps nor overflows the end offset.Left unchanged, because existing tests assert it: a start of zero or less, or past the end,
returns the input; a negative
FORleaves no tail.Verifying this change
This change added tests and can be verified as follows:
ScalarFunctionsTest#testOverlay, all failing without the fix.ScalarFunctionsTestandSqlExpressionTestpass, including the 18 existingOVERLAYexpectations.argument combinations covering the start and length boundaries: no differences.
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noReplacing in a short string is faster (46 ns to 29 ns), one exactly-sized
char[]instead of agrowing
StringBuilder. Replacing near the tail of a 2000-character string is slower (940 ns to2021 ns): converting a code point position to a char offset needs the same walk
SUBSTRINGdoes.Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5)