test: add regression tests for LIKE operator backtracking (#409) - #449
Open
chenjunwenhao wants to merge 1 commit into
Open
Conversation
Issue alibaba#409 reported that v3's OperatorLike.matchPattern used a greedy segment-matching algorithm without backtracking, causing patterns like "a%c" on input "abc" to incorrectly return false. v4 fixed this with a proper backtracking algorithm using sRecall/pRecall pointers in BaseBinaryOperator.matchPattern. However, no regression tests existed for these backtracking edge cases. This commit adds: - Issue409RegressionTest.java: 14 JUnit tests covering backtracking, multi-wildcard, trailing/leading %, empty strings, null handling, and conditional expressions - like.ql: 14 additional QL assertions for backtracking scenarios 🤖 Generated with [Qoder][https://qoder.com]
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.
Summary
Issue #409 reported that v3's
OperatorLike.matchPatternused a greedy segment-matching algorithm without backtracking, causing patterns like"abc" like "a%c"to incorrectly returnfalse.v4 fixed this by replacing the greedy algorithm with a proper backtracking matcher using
sRecall/pRecallpointers inBaseBinaryOperator.matchPattern. However, no regression tests existed for these backtracking edge cases.This PR adds comprehensive regression tests to prevent the v3 bug from silently regressing.
Changes
New file:
src/test/java/.../issue/Issue409RegressionTest.java14 JUnit tests organized by category:
"abc" like "a%c", variable-based"aXbYc" like "a%b%c", repeated prefix%"1%1" like "1%","%6""" like "%","" like "%%""abc" like "a%d","%x%"not_likeinversenot_likeis exact inversenull like null,"a" like nullifand with&&Updated:
src/test/resources/.../operator/like.ql14 additional QL-level assertions covering backtracking, multi-wildcard, trailing
%, and negative cases.Why This Matters
The v3 bug was subtle — it only manifests when the greedy first-match of a wildcard segment is suboptimal. The existing test
"ABCD" like "A%B%D"passes even with the buggy v3 algorithm because each segment's first occurrence happens to be the correct one. Without explicit backtracking tests, a future refactor could reintroduce the bug undetected.Fixes #409