Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,22 @@ private Stream<TestSetSpec> withEscape() {
DataTypes.STRING(),
DataTypes.STRING())
// Empty strings in pattern or escape
.testSqlResult("f0 LIKE 'test\"end' ESCAPE ''", false, DataTypes.BOOLEAN())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason of this line removal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was not deleted, but placed on line 153
This is arranged according to the pattern-ESCAPE-escape format, with three tests being

empty ESCAPE empty
empty ESCAPE non-empty
non-empty ESCAPE empty

.testSqlResult("f0 LIKE '' ESCAPE ''", false, DataTypes.BOOLEAN())
.testSqlResult("f0 LIKE '' ESCAPE '!'", false, DataTypes.BOOLEAN())
.testSqlResult("f0 LIKE 'test\"end' ESCAPE ''", false, DataTypes.BOOLEAN())
// Escaped _ in quick path: startsWith (BEGIN_PATTERN)
.testSqlResult("f2 LIKE 'te!_%' ESCAPE '!'", true, DataTypes.BOOLEAN())
.testSqlResult("f0 LIKE 'te!_%' ESCAPE '!'", false, DataTypes.BOOLEAN())

// Escaped _ in quick path: endsWith (END_PATTERN)
.testSqlResult("f2 LIKE '%!_st' ESCAPE '!'", true, DataTypes.BOOLEAN())

// Escaped _ in quick path: contains (MIDDLE_PATTERN)
.testSqlResult("f2 LIKE '%!_s%' ESCAPE '!'", true, DataTypes.BOOLEAN())

// Escaped _ in quick path: multi-segment (ChainChecker)
.testSqlResult("f2 LIKE 'te!_%st' ESCAPE '!'", true, DataTypes.BOOLEAN())
.testSqlResult("f0 LIKE 'te!_%st' ESCAPE '!'", false, DataTypes.BOOLEAN())
Comment on lines +152 to +166
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does any of this test fail without a fix?

Copy link
Copy Markdown
Contributor Author

@Au-Miner Au-Miner Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, this is not a bug fix, but a technical debt
These tests are designed to increase the coverage of the tests

// Escaping with emoji
.testSqlResult("f0 LIKE 'test' ESCAPE '✅'", true, DataTypes.BOOLEAN())
.testSqlResult("f1 LIKE 'test✅%' ESCAPE '✅'", true, DataTypes.BOOLEAN())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class SqlLikeChainChecker {
private final int[] midLens;
private final int beginLen;
private final int endLen;
private final boolean leftAnchor;
private final boolean rightAnchor;
private final boolean isEmptyPattern;

public SqlLikeChainChecker(String pattern) {
final StringTokenizer tokens = new StringTokenizer(pattern, "%");
leftAnchor = !pattern.startsWith("%");
rightAnchor = !pattern.endsWith("%");
boolean leftAnchor = !pattern.startsWith("%");
boolean rightAnchor = !pattern.endsWith("%");
isEmptyPattern = pattern.isEmpty();
int len = 0;
// at least 2 checkers always
BinaryStringData leftPattern = null;
Expand All @@ -63,7 +63,7 @@ public SqlLikeChainChecker(String pattern) {

for (int i = 0; tokens.hasMoreTokens(); i++) {
String chunk = tokens.nextToken();
if (chunk.length() == 0) {
if (chunk.isEmpty()) {
// %% is folded in the .*?.*? regex usually into .*?
continue;
}
Expand Down Expand Up @@ -97,13 +97,8 @@ public boolean check(BinaryStringData str) {
int mark = str.getSizeInBytes();
// Returns false early if either:
// the input is too short to match the pattern, or
// the pattern is empty (or anchored with no literals) but the input is not empty.
if (mark < minLen
|| beginPattern == null
&& endPattern == null
&& middlePatterns.length == 0
&& mark > 0
&& (leftAnchor || rightAnchor)) {
// the pattern is empty but the input is not.
if (mark < minLen || mark > 0 && isEmptyPattern) {
return false;
}
// prefix, extend start
Expand Down