Fix negative from index handling in INSTR - #820
Draft
lkxdsb wants to merge 1 commit into
Draft
Conversation
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 changes were proposed in this pull request?
This PR fixes
INSTRwhen thefromargument is negative.fromas a position counted backward from the end of the stringnthmatching occurrence0when no occurrence can be foundStringandBinaryStringoverloadsfrom,from = 0, invalidnth, and null argumentsWhy are the changes needed?
The previous implementation always converted
fromto a zero-based forward-search index:A negative value therefore entered the invalid-index branch and returned
null, instead of locating a starting position from the end of the string and searching backward. This produced incorrect results for the negative-index behavior described in #87.Fixes #87
Behavior after this change
INSTR('abcabc', 'a', -1, 1)4awhen searching backward from the endINSTR('abcabc', 'a', -1, 2)1aencountered while searching backwardINSTR('abcabc', 'c', -3, 1)3-3INSTR('aaaa', 'aa', -1, 2)2INSTR('abcabc', 'a', -7, 1)0Implementation details
Stringoverload usesString.lastIndexOffor the negative search path.BinaryStringdoes not providelastIndexOf, so the implementation retains the last forward match not beyond the requested starting position.BinaryStringscan by one character preserves overlapping matches.How was this PR tested?
Unit test
Result:
The unit test covers negative positions, multiple backward matches, overlapping matches, out-of-range positions, multibyte strings, and both input types.
Local runtime integration test
Result:
This test starts the local GeaFlow environment, submits the SQL through
GQLPipeLine, executes it with the file connector, and compares the generated Sink output with the expected result:Additional checks
0 violations0 unapproved licensesgit diff --check: passed