Skip to content

Commit f39ef12

Browse files
Switch to old function where possible, add more UTs
1 parent 0518bbc commit f39ef12

File tree

4 files changed

+221
-13
lines changed

4 files changed

+221
-13
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/where-like.csv-spec

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,30 @@ emp_no:integer | first_name:keyword
7575
;
7676

7777
likeListEmptyArgWildcard
78+
required_capability: like_with_list_of_patterns
7879
from employees | where first_name like ("") | keep emp_no, first_name;
7980

8081
emp_no:integer | first_name:keyword
8182
;
8283

8384
likeListSingleArgWildcard
85+
required_capability: like_with_list_of_patterns
8486
from employees | where first_name like ("Eberhardt*") | keep emp_no, first_name;
8587

8688
emp_no:integer | first_name:keyword
8789
10013 | Eberhardt
8890
;
8991

9092
likeListTwoArgWildcard
93+
required_capability: like_with_list_of_patterns
9194
from employees | where first_name like ("Eberhardt*", "testString*") | keep emp_no, first_name;
9295

9396
emp_no:integer | first_name:keyword
9497
10013 | Eberhardt
9598
;
9699

97100
likeListThreeArgWildcard
101+
required_capability: like_with_list_of_patterns
98102
from employees | where first_name like ("Eberhardt*", "Ot*", "Part?") | keep emp_no, first_name;
99103

100104
emp_no:integer | first_name:keyword
@@ -105,6 +109,7 @@ emp_no:integer | first_name:keyword
105109

106110

107111
likeListMultipleWhere
112+
required_capability: like_with_list_of_patterns
108113
from employees | where first_name like ("Eberhardt*", "Ot*", "Part?") | where first_name like ("Eberhard?", "Otm*")| keep emp_no, first_name;
109114

110115
emp_no:integer | first_name:keyword
@@ -113,6 +118,7 @@ emp_no:integer | first_name:keyword
113118
;
114119

115120
likeListAllWildcard
121+
required_capability: like_with_list_of_patterns
116122
from employees | where first_name like ("*") | keep emp_no, first_name | sort emp_no | limit 2;
117123

118124
emp_no:integer | first_name:keyword
@@ -121,19 +127,22 @@ emp_no:integer | first_name:keyword
121127
;
122128

123129
likeListOverlappingPatterns
130+
required_capability: like_with_list_of_patterns
124131
from employees | where first_name like ("Eber*", "Eberhardt") | keep emp_no, first_name;
125132

126133
emp_no:integer | first_name:keyword
127134
10013 | Eberhardt
128135
;
129136

130137
likeListCaseSensitive
138+
required_capability: like_with_list_of_patterns
131139
from employees | where first_name like ("eberhardt", "EBERHARDT") | keep emp_no, first_name;
132140

133141
emp_no:integer | first_name:keyword
134142
;
135143

136144
likeListSpecialCharacters
145+
required_capability: like_with_list_of_patterns
137146
from employees | where first_name like ("*ar*", "?eor*") | keep emp_no, first_name | sort emp_no;
138147

139148
emp_no:integer | first_name:keyword
@@ -153,18 +162,212 @@ emp_no:integer | first_name:keyword
153162
;
154163

155164
likeListEscapedWildcard
165+
required_capability: like_with_list_of_patterns
156166
from employees | where first_name like ("Eberhar\\*") | keep emp_no, first_name;
157167

158168
emp_no:integer | first_name:keyword
159169
;
160170

161171
likeEvalNoWildcard
172+
required_capability: like_with_list_of_patterns
162173
from employees | eval x = concat(first_name, "X") | where x like "EberhardtX" | keep emp_no, first_name;
163174

164175
emp_no:integer | first_name:keyword
165176
10013 | Eberhardt
166177
;
167178

179+
likeListNineOrMoreLetters
180+
required_capability: like_with_list_of_patterns
181+
from employees | where first_name like ("?????????*") | keep emp_no, first_name | sort emp_no;
182+
183+
emp_no:integer | first_name:keyword
184+
10004 | Chirstian
185+
10010 | Duangkaew
186+
10013 | Eberhardt
187+
10017 | Cristinel
188+
10025 | Prasadram
189+
10059 | Alejandro
190+
10069 | Margareta
191+
10089 | Sudharsan
192+
10092 | Valdiodio
193+
10098 | Sreekrishna
194+
;
195+
196+
notLikeListThreeArgWildcardNotOtherFilter
197+
required_capability: like_with_list_of_patterns
198+
from employees | where first_name not like ("Eberhardt*", "Ot*", "Part?") and emp_no < 10010 | keep emp_no, first_name;
199+
200+
emp_no:integer | first_name:keyword
201+
10001 | Georgi
202+
10002 | Bezalel
203+
10004 | Chirstian
204+
10005 | Kyoichi
205+
10006 | Anneke
206+
10007 | Tzvetan
207+
10008 | Saniya
208+
10009 | Sumant
209+
;
210+
211+
notLikeListThreeArgWildcardOtherFirst
212+
required_capability: like_with_list_of_patterns
213+
from employees | where emp_no < 10010 and first_name not like ("Eberhardt*", "Ot*", "Part?") | keep emp_no, first_name;
214+
215+
emp_no:integer | first_name:keyword
216+
10001 | Georgi
217+
10002 | Bezalel
218+
10004 | Chirstian
219+
10005 | Kyoichi
220+
10006 | Anneke
221+
10007 | Tzvetan
222+
10008 | Saniya
223+
10009 | Sumant
224+
;
225+
226+
notLikeFiveOrLessLetters
227+
required_capability: like_with_list_of_patterns
228+
from employees | where first_name not like ("??????*") | keep emp_no, first_name | sort emp_no;
229+
230+
emp_no:integer | first_name:keyword
231+
10003 | Parto
232+
10011 | Mary
233+
10014 | Berni
234+
10021 | Ramzi
235+
10023 | Bojan
236+
10029 | Otmar
237+
10040 | Weiyi
238+
10041 | Uri
239+
10042 | Magy
240+
10045 | Moss
241+
10049 | Basil
242+
10057 | Ebbe
243+
10061 | Tse
244+
10063 | Gino
245+
10064 | Udi
246+
10066 | Kwee
247+
10071 | Hisao
248+
10073 | Shir
249+
10075 | Gao
250+
10076 | Erez
251+
10077 | Mona
252+
10078 | Danel
253+
10083 | Vishv
254+
10084 | Tuval
255+
10097 | Remzi
256+
;
257+
258+
notLikeListMultipleWhere
259+
required_capability: like_with_list_of_patterns
260+
from employees | where first_name not like ("Eberhardt*", "Ot*", "Part?", "A*", "B*", "C*", "D*") | where first_name not like ("Eberhard?", "Otm*", "F*", "G*", "H*", "I*", "J*", "K*", "L*")| keep emp_no, first_name;
261+
262+
emp_no:integer | first_name:keyword
263+
10007 | Tzvetan
264+
10008 | Saniya
265+
10009 | Sumant
266+
10011 | Mary
267+
10012 | Patricio
268+
10020 | Mayuko
269+
10021 | Ramzi
270+
10022 | Shahaf
271+
10024 | Suzette
272+
10025 | Prasadram
273+
10026 | Yongqiao
274+
10040 | Weiyi
275+
10041 | Uri
276+
10042 | Magy
277+
10043 | Yishay
278+
10044 | Mingsen
279+
10045 | Moss
280+
10047 | Zvonko
281+
10050 | Yinghua
282+
10053 | Sanjiv
283+
10054 | Mayumi
284+
10057 | Ebbe
285+
10061 | Tse
286+
10064 | Udi
287+
10065 | Satosi
288+
10069 | Margareta
289+
10070 | Reuven
290+
10073 | Shir
291+
10074 | Mokhtar
292+
10076 | Erez
293+
10077 | Mona
294+
10080 | Premal
295+
10081 | Zhongwei
296+
10082 | Parviz
297+
10083 | Vishv
298+
10084 | Tuval
299+
10086 | Somnath
300+
10087 | Xinglin
301+
10089 | Sudharsan
302+
10092 | Valdiodio
303+
10093 | Sailaja
304+
10097 | Remzi
305+
10098 | Sreekrishna
306+
10099 | Valter
307+
;
308+
309+
notLikeListAllWildcard
310+
required_capability: like_with_list_of_patterns
311+
from employees | where first_name not like ("*") | keep emp_no, first_name | sort emp_no | limit 2;
312+
313+
emp_no:integer | first_name:keyword
314+
10030 | null
315+
10031 | null
316+
;
317+
318+
notLikeListWildcard
319+
required_capability: like_with_list_of_patterns
320+
from employees | where first_name not like ("A*","B*", "C*", "D*","E*", "F*", "G*", "H*", "I*", "J*", "K*") | keep emp_no, first_name;
321+
322+
emp_no:integer | first_name:keyword
323+
10003 | Parto
324+
10007 | Tzvetan
325+
10008 | Saniya
326+
10009 | Sumant
327+
10011 | Mary
328+
10012 | Patricio
329+
10019 | Lillian
330+
10020 | Mayuko
331+
10021 | Ramzi
332+
10022 | Shahaf
333+
10024 | Suzette
334+
10025 | Prasadram
335+
10026 | Yongqiao
336+
10029 | Otmar
337+
10040 | Weiyi
338+
10041 | Uri
339+
10042 | Magy
340+
10043 | Yishay
341+
10044 | Mingsen
342+
10045 | Moss
343+
10046 | Lucien
344+
10047 | Zvonko
345+
10050 | Yinghua
346+
10053 | Sanjiv
347+
10054 | Mayumi
348+
10061 | Tse
349+
10064 | Udi
350+
10065 | Satosi
351+
10069 | Margareta
352+
10070 | Reuven
353+
10073 | Shir
354+
10074 | Mokhtar
355+
10077 | Mona
356+
10080 | Premal
357+
10081 | Zhongwei
358+
10082 | Parviz
359+
10083 | Vishv
360+
10084 | Tuval
361+
10086 | Somnath
362+
10087 | Xinglin
363+
10089 | Sudharsan
364+
10092 | Valdiodio
365+
10093 | Sailaja
366+
10097 | Remzi
367+
10098 | Sreekrishna
368+
10099 | Valter
369+
;
370+
168371

169372
likeAll
170373
from employees | where first_name like "*" and emp_no > 10028 | sort emp_no | keep emp_no, first_name | limit 2;

x-pack/plugin/esql/src/main/antlr/parser/Expression.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ booleanExpression
1818
;
1919

2020
regexBooleanExpression
21-
: valueExpression (NOT)? LIKE valueExpression #likeExpression
22-
| valueExpression (NOT)? RLIKE valueExpression #rlikeExpression
23-
| valueExpression (NOT)? LIKE LP valueExpression (COMMA valueExpression)* RP #logicalLikeList
21+
: valueExpression (NOT)? LIKE valueExpression #likeExpression
22+
| valueExpression (NOT)? RLIKE valueExpression #rlikeExpression
23+
| valueExpression (NOT)? LIKE LP valueExpression (COMMA valueExpression)* RP #logicalLikeList
2424
;
2525

2626
matchBooleanExpression

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,14 @@ public enum Cap {
11851185
/**
11861186
* MATCH PHRASE function
11871187
*/
1188-
MATCH_PHRASE_FUNCTION(Build.current().isSnapshot());
1188+
MATCH_PHRASE_FUNCTION(Build.current().isSnapshot()),
1189+
1190+
/**
1191+
* Allows LIKE to take a list of patterns to match against
1192+
*/
1193+
LIKE_WITH_LIST_OF_PATTERNS;
1194+
1195+
11891196

11901197
private final boolean enabled;
11911198

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,10 @@ public Expression visitLogicalLikeList(EsqlBaseParser.LogicalLikeListContext ctx
739739
List <WildcardPattern> wildcardPatterns = expressions.subList(1, expressions.size()).stream()
740740
.map(x->new WildcardPattern(x.fold(FoldContext.small()).toString()))
741741
.toList();
742-
//Expression e = wildcardPatterns.size() == 1
743-
// ? new WildcardLike( source, expressions.getFirst(),wildcardPatterns.getFirst())
744-
// : new WildcardLikeList(source, expressions.getFirst(), new WildcardPatternList(wildcardPatterns));
745-
Expression e = new WildcardLikeList(source, expressions.getFirst(), new WildcardPatternList(wildcardPatterns));
742+
//for now we will use the old WildcardLike function as much as possible to allow compatibility in mixed version deployments
743+
Expression e = wildcardPatterns.size() == 1
744+
? new WildcardLike( source, expressions.getFirst(),wildcardPatterns.getFirst())
745+
: new WildcardLikeList(source, expressions.getFirst(), new WildcardPatternList(wildcardPatterns));
746746
return ctx.NOT() == null ? e : new Not(source, e);
747747
}
748748

@@ -757,12 +757,10 @@ public Object visitIsNull(EsqlBaseParser.IsNullContext ctx) {
757757
public Expression visitLikeExpression(EsqlBaseParser.LikeExpressionContext ctx){
758758
Source source = source(ctx);
759759
List<Expression> expressions = ctx.valueExpression().stream().map(this::expression).toList();
760-
/*WildcardLike result = new WildcardLike(
761-
source,
762-
expressions.get(0),
763-
new WildcardPattern(expressions.get(1).fold(FoldContext.small() ).toString()));*/
764760
WildcardPattern pattern = new WildcardPattern(expressions.get(1).fold(FoldContext.small() ).toString());
765-
WildcardLikeList result = new WildcardLikeList(source, expressions.getFirst(), new WildcardPatternList(List.of(pattern)));
761+
//for now we will use the old WildcardLike function as much as possible to allow compatibility in mixed version deployments
762+
WildcardLike result = new WildcardLike(source, expressions.get(0), pattern);
763+
//WildcardLikeList result = new WildcardLikeList(source, expressions.getFirst(), new WildcardPatternList(List.of(pattern)));
766764
return ctx.NOT() == null ? result : new Not(source, result);
767765
}
768766

0 commit comments

Comments
 (0)