Skip to content

test: add regression tests for LIKE operator backtracking (#409) - #449

Open
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:test/issue-409-like-operator-backtracking-regression
Open

test: add regression tests for LIKE operator backtracking (#409)#449
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:test/issue-409-like-operator-backtracking-regression

Conversation

@chenjunwenhao

Copy link
Copy Markdown
Contributor

Summary

Issue #409 reported that v3's OperatorLike.matchPattern used a greedy segment-matching algorithm without backtracking, causing patterns like "abc" like "a%c" to incorrectly return false.

v4 fixed this by replacing the greedy algorithm with a proper backtracking matcher using sRecall/pRecall pointers in BaseBinaryOperator.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.java

14 JUnit tests organized by category:

Category Tests Key Cases
Core backtracking 2 "abc" like "a%c", variable-based
Multi-segment backtracking 2 "aXbYc" like "a%b%c", repeated prefix
Trailing/leading % 2 "1%1" like "1%", "%6"
Empty string & wildcards 1 "" like "%", "" like "%%"
Negative cases 1 "abc" like "a%d", "%x%"
not_like inverse 1 Verifies not_like is exact inverse
Null handling 1 null like null, "a" like null
Conditional/logical 2 LIKE in if and with &&

Updated: src/test/resources/.../operator/like.ql

14 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

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]
@CLAassistant

CLAassistant commented Jun 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.3.4版本的OperatorLike的matchPattern方法有BUG

2 participants