Skip to content

Commit b769c5e

Browse files
ES|QL: remove dead code for LIKE operator (#115037) (#115192)
1 parent b80f677 commit b769c5e

File tree

7 files changed

+54
-236
lines changed

7 files changed

+54
-236
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/Like.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/LikePattern.java

Lines changed: 0 additions & 95 deletions
This file was deleted.

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/planner/ExpressionTranslators.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
2020
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull;
2121
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNull;
22-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.Like;
2322
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
2423
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RegexMatch;
2524
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike;
@@ -66,9 +65,6 @@ public static Query doTranslate(RegexMatch e, TranslatorHandler handler) {
6665
}
6766

6867
private static Query translateField(RegexMatch e, String targetFieldName) {
69-
if (e instanceof Like l) {
70-
return new WildcardQuery(e.source(), targetFieldName, l.pattern().asLuceneWildcard(), l.caseInsensitive());
71-
}
7268
if (e instanceof WildcardLike l) {
7369
return new WildcardQuery(e.source(), targetFieldName, l.pattern().asLuceneWildcard(), l.caseInsensitive());
7470
}

x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/StringPatternTests.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,78 @@
1212

1313
public class StringPatternTests extends ESTestCase {
1414

15-
private LikePattern like(String pattern, char escape) {
16-
return new LikePattern(pattern, escape);
15+
private WildcardPattern like(String pattern) {
16+
return new WildcardPattern(pattern);
1717
}
1818

1919
private RLikePattern rlike(String pattern) {
2020
return new RLikePattern(pattern);
2121
}
2222

23-
private boolean matchesAll(String pattern, char escape) {
24-
return like(pattern, escape).matchesAll();
23+
private boolean likeMatchesAll(String pattern) {
24+
return like(pattern).matchesAll();
2525
}
2626

27-
private boolean exactMatch(String pattern, char escape) {
28-
String escaped = pattern.replace(Character.toString(escape), StringUtils.EMPTY);
29-
return escaped.equals(like(pattern, escape).exactMatch());
27+
private boolean likeExactMatch(String pattern) {
28+
String escaped = pattern.replace("\\", StringUtils.EMPTY);
29+
return escaped.equals(like(pattern).exactMatch());
3030
}
3131

32-
private boolean matchesAll(String pattern) {
32+
private boolean rlikeMatchesAll(String pattern) {
3333
return rlike(pattern).matchesAll();
3434
}
3535

36-
private boolean exactMatch(String pattern) {
36+
private boolean rlikeExactMatch(String pattern) {
3737
return pattern.equals(rlike(pattern).exactMatch());
3838
}
3939

40-
public void testWildcardMatchAll() throws Exception {
41-
assertTrue(matchesAll("%", '0'));
42-
assertTrue(matchesAll("%%", '0'));
40+
public void testWildcardMatchAll() {
41+
assertTrue(likeMatchesAll("*"));
42+
assertTrue(likeMatchesAll("**"));
4343

44-
assertFalse(matchesAll("a%", '0'));
45-
assertFalse(matchesAll("%_", '0'));
46-
assertFalse(matchesAll("%_%_%", '0'));
47-
assertFalse(matchesAll("_%", '0'));
48-
assertFalse(matchesAll("0%", '0'));
44+
assertFalse(likeMatchesAll("a*"));
45+
assertFalse(likeMatchesAll("*?"));
46+
assertFalse(likeMatchesAll("*?*?*"));
47+
assertFalse(likeMatchesAll("?*"));
48+
assertFalse(likeMatchesAll("\\*"));
4949
}
5050

51-
public void testRegexMatchAll() throws Exception {
52-
assertTrue(matchesAll(".*"));
53-
assertTrue(matchesAll(".*.*"));
54-
assertTrue(matchesAll(".*.?"));
55-
assertTrue(matchesAll(".?.*"));
56-
assertTrue(matchesAll(".*.?.*"));
51+
public void testRegexMatchAll() {
52+
assertTrue(rlikeMatchesAll(".*"));
53+
assertTrue(rlikeMatchesAll(".*.*"));
54+
assertTrue(rlikeMatchesAll(".*.?"));
55+
assertTrue(rlikeMatchesAll(".?.*"));
56+
assertTrue(rlikeMatchesAll(".*.?.*"));
5757

58-
assertFalse(matchesAll("..*"));
59-
assertFalse(matchesAll("ab."));
60-
assertFalse(matchesAll("..?"));
58+
assertFalse(rlikeMatchesAll("..*"));
59+
assertFalse(rlikeMatchesAll("ab."));
60+
assertFalse(rlikeMatchesAll("..?"));
6161
}
6262

63-
public void testWildcardExactMatch() throws Exception {
64-
assertTrue(exactMatch("0%", '0'));
65-
assertTrue(exactMatch("0_", '0'));
66-
assertTrue(exactMatch("123", '0'));
67-
assertTrue(exactMatch("1230_", '0'));
68-
assertTrue(exactMatch("1230_321", '0'));
69-
70-
assertFalse(exactMatch("%", '0'));
71-
assertFalse(exactMatch("%%", '0'));
72-
assertFalse(exactMatch("a%", '0'));
73-
assertFalse(exactMatch("a_", '0'));
63+
public void testWildcardExactMatch() {
64+
assertTrue(likeExactMatch("\\*"));
65+
assertTrue(likeExactMatch("\\?"));
66+
assertTrue(likeExactMatch("123"));
67+
assertTrue(likeExactMatch("123\\?"));
68+
assertTrue(likeExactMatch("123\\?321"));
69+
70+
assertFalse(likeExactMatch("*"));
71+
assertFalse(likeExactMatch("**"));
72+
assertFalse(likeExactMatch("a*"));
73+
assertFalse(likeExactMatch("a?"));
7474
}
7575

76-
public void testRegexExactMatch() throws Exception {
77-
assertFalse(exactMatch(".*"));
78-
assertFalse(exactMatch(".*.*"));
79-
assertFalse(exactMatch(".*.?"));
80-
assertFalse(exactMatch(".?.*"));
81-
assertFalse(exactMatch(".*.?.*"));
82-
assertFalse(exactMatch("..*"));
83-
assertFalse(exactMatch("ab."));
84-
assertFalse(exactMatch("..?"));
85-
86-
assertTrue(exactMatch("abc"));
87-
assertTrue(exactMatch("12345"));
76+
public void testRegexExactMatch() {
77+
assertFalse(rlikeExactMatch(".*"));
78+
assertFalse(rlikeExactMatch(".*.*"));
79+
assertFalse(rlikeExactMatch(".*.?"));
80+
assertFalse(rlikeExactMatch(".?.*"));
81+
assertFalse(rlikeExactMatch(".*.?.*"));
82+
assertFalse(rlikeExactMatch("..*"));
83+
assertFalse(rlikeExactMatch("ab."));
84+
assertFalse(rlikeExactMatch("..?"));
85+
86+
assertTrue(rlikeExactMatch("abc"));
87+
assertTrue(rlikeExactMatch("12345"));
8888
}
8989
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ConstantFoldingTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.And;
1818
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Not;
1919
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
20-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.Like;
21-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.LikePattern;
2220
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
2321
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
2422
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike;
@@ -101,7 +99,6 @@ public void testConstantNot() {
10199
}
102100

103101
public void testConstantFoldingLikes() {
104-
assertEquals(TRUE, new ConstantFolding().rule(new Like(EMPTY, of("test_emp"), new LikePattern("test%", (char) 0))).canonical());
105102
assertEquals(TRUE, new ConstantFolding().rule(new WildcardLike(EMPTY, of("test_emp"), new WildcardPattern("test*"))).canonical());
106103
assertEquals(TRUE, new ConstantFolding().rule(new RLike(EMPTY, of("test_emp"), new RLikePattern("test.emp"))).canonical());
107104
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceRegexMatchTests.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.elasticsearch.xpack.esql.core.expression.Expression;
1212
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
1313
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull;
14-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.Like;
15-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.LikePattern;
1614
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
1715
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
1816
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike;
@@ -26,18 +24,6 @@
2624

2725
public class ReplaceRegexMatchTests extends ESTestCase {
2826

29-
public void testMatchAllLikeToExist() {
30-
for (String s : asList("%", "%%", "%%%")) {
31-
LikePattern pattern = new LikePattern(s, (char) 0);
32-
FieldAttribute fa = getFieldAttribute();
33-
Like l = new Like(EMPTY, fa, pattern);
34-
Expression e = new ReplaceRegexMatch().rule(l);
35-
assertEquals(IsNotNull.class, e.getClass());
36-
IsNotNull inn = (IsNotNull) e;
37-
assertEquals(fa, inn.field());
38-
}
39-
}
40-
4127
public void testMatchAllWildcardLikeToExist() {
4228
for (String s : asList("*", "**", "***")) {
4329
WildcardPattern pattern = new WildcardPattern(s);
@@ -60,31 +46,19 @@ public void testMatchAllRLikeToExist() {
6046
assertEquals(fa, inn.field());
6147
}
6248

63-
public void testExactMatchLike() {
64-
for (String s : asList("ab", "ab0%", "ab0_c")) {
65-
LikePattern pattern = new LikePattern(s, '0');
49+
public void testExactMatchWildcardLike() {
50+
for (String s : asList("ab", "ab\\*", "ab\\?c")) {
51+
WildcardPattern pattern = new WildcardPattern(s);
6652
FieldAttribute fa = getFieldAttribute();
67-
Like l = new Like(EMPTY, fa, pattern);
53+
WildcardLike l = new WildcardLike(EMPTY, fa, pattern);
6854
Expression e = new ReplaceRegexMatch().rule(l);
6955
assertEquals(Equals.class, e.getClass());
7056
Equals eq = (Equals) e;
7157
assertEquals(fa, eq.left());
72-
assertEquals(s.replace("0", StringUtils.EMPTY), eq.right().fold());
58+
assertEquals(s.replace("\\", StringUtils.EMPTY), eq.right().fold());
7359
}
7460
}
7561

76-
public void testExactMatchWildcardLike() {
77-
String s = "ab";
78-
WildcardPattern pattern = new WildcardPattern(s);
79-
FieldAttribute fa = getFieldAttribute();
80-
WildcardLike l = new WildcardLike(EMPTY, fa, pattern);
81-
Expression e = new ReplaceRegexMatch().rule(l);
82-
assertEquals(Equals.class, e.getClass());
83-
Equals eq = (Equals) e;
84-
assertEquals(fa, eq.left());
85-
assertEquals(s, eq.right().fold());
86-
}
87-
8862
public void testExactMatchRLike() {
8963
RLikePattern pattern = new RLikePattern("abc");
9064
FieldAttribute fa = getFieldAttribute();

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/tree/EsqlNodeSubclassTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.elasticsearch.xpack.esql.core.expression.UnresolvedNamedExpression;
2929
import org.elasticsearch.xpack.esql.core.expression.function.Function;
3030
import org.elasticsearch.xpack.esql.core.expression.predicate.fulltext.FullTextPredicate;
31-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.Like;
32-
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.LikePattern;
3331
import org.elasticsearch.xpack.esql.core.tree.AbstractNodeTestCase;
3432
import org.elasticsearch.xpack.esql.core.tree.Node;
3533
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
@@ -422,12 +420,6 @@ public void accept(Page page) {
422420
}
423421
return b.toString();
424422
}
425-
} else if (toBuildClass == Like.class) {
426-
427-
if (argClass == LikePattern.class) {
428-
return new LikePattern(randomAlphaOfLength(16), randomFrom('\\', '|', '/', '`'));
429-
}
430-
431423
} else if (argClass == Dissect.Parser.class) {
432424
// Dissect.Parser is a record / final, cannot be mocked
433425
String pattern = randomDissectPattern();

0 commit comments

Comments
 (0)