Skip to content

Commit 15dfed3

Browse files
Migrate tests from VerifierTests to 230_folding.yml
1 parent 8e2c6b4 commit 15dfed3

File tree

2 files changed

+187
-36
lines changed

2 files changed

+187
-36
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,31 +2175,6 @@ private void checkFullTextFunctionNullArgs(String functionInvocation, String arg
21752175
);
21762176
}
21772177

2178-
public void testFullTextFunctionsConstantArg() throws Exception {
2179-
checkFullTextFunctionsConstantArg("match(title, category)", "second");
2180-
checkFullTextFunctionsConstantArg("qstr(title)", "");
2181-
checkFullTextFunctionsConstantArg("kql(title)", "");
2182-
checkFullTextFunctionsConstantArg("match_phrase(title, tags)", "second");
2183-
if (EsqlCapabilities.Cap.MULTI_MATCH_FUNCTION.isEnabled()) {
2184-
checkFullTextFunctionsConstantArg("multi_match(category, body)", "first");
2185-
checkFullTextFunctionsConstantArg("multi_match(concat(title, \"world\"), title)", "first");
2186-
}
2187-
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {
2188-
checkFullTextFunctionsConstantArg("term(title, tags)", "second");
2189-
}
2190-
if (EsqlCapabilities.Cap.KNN_FUNCTION_V2.isEnabled()) {
2191-
checkFullTextFunctionsConstantArg("knn(vector, vector, 10)", "second");
2192-
checkFullTextFunctionsConstantArg("knn(vector, [0, 1, 2], category)", "third");
2193-
}
2194-
}
2195-
2196-
private void checkFullTextFunctionsConstantArg(String functionInvocation, String argOrdinal) throws Exception {
2197-
assertThat(
2198-
error("from test | where " + functionInvocation, fullTextAnalyzer),
2199-
containsString(argOrdinal + " argument of [" + functionInvocation + "] must be a constant")
2200-
);
2201-
}
2202-
22032178
public void testInsistNotOnTopOfFrom() {
22042179
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
22052180

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/230_folding.yml

Lines changed: 187 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
setup:
33
- requires:
44
test_runner_features: [ capabilities, contains ]
5-
capabilities:
6-
- method: POST
7-
path: /_query
8-
parameters: [ ]
9-
capabilities: [ agg_top ]
10-
reason: "uses TOP function in STATS aggregation"
5+
reason: "make sure new functions run where supported only"
116
- do:
127
indices.create:
138
index: employees
@@ -43,7 +38,16 @@ setup:
4338
- { "hire_date": "2019-01-01", "salary_change": 50.5, "salary": 40000, "salary_change_long": 50, "name": "Charlie Smith", "image_vector": [ 0.7, 0.8, 0.9 ] }
4439

4540
---
46-
Top function with constant folding:
41+
TOP function with constant folding:
42+
- requires:
43+
test_runner_features: [ capabilities ]
44+
capabilities:
45+
- method: POST
46+
path: /_query
47+
parameters: [ ]
48+
capabilities: [ agg_top ]
49+
reason: "Uses TOP function"
50+
4751
- do:
4852
esql.query:
4953
body:
@@ -70,7 +74,15 @@ Top function with constant folding:
7074

7175
---
7276

73-
Top function with negative limit value after folding:
77+
TOP function with negative limit value after folding:
78+
- requires:
79+
test_runner_features: [ capabilities ]
80+
capabilities:
81+
- method: POST
82+
path: /_query
83+
parameters: [ ]
84+
capabilities: [ agg_top ]
85+
reason: "Uses TOP function"
7486
- do:
7587
catch: bad_request
7688
esql.query:
@@ -89,6 +101,14 @@ Top function with negative limit value after folding:
89101
---
90102

91103
Top function with invalid sort order:
104+
- requires:
105+
test_runner_features: [ capabilities ]
106+
capabilities:
107+
- method: POST
108+
path: /_query
109+
parameters: [ ]
110+
capabilities: [ agg_top ]
111+
reason: "Uses TOP function"
92112
- do:
93113
catch: bad_request
94114
esql.query:
@@ -106,7 +126,7 @@ Top function with invalid sort order:
106126

107127
---
108128

109-
Sample function with constant folding:
129+
SAMPLE function with constant folding:
110130
- do:
111131
esql.query:
112132
body:
@@ -173,7 +193,7 @@ Match function with non-foldable query:
173193

174194
---
175195

176-
Foldable query using PHRASE_MATCH on name:
196+
Foldable query using MATCH_PHRASE on name:
177197
- do:
178198
esql.query:
179199
body:
@@ -196,7 +216,7 @@ Foldable query using PHRASE_MATCH on name:
196216

197217
---
198218

199-
Foldable query using PHRASE_MATCH on name but with non-foldable expression:
219+
Foldable query using MATCH_PHRASE on name but with non-foldable expression:
200220
- do:
201221
catch: bad_request
202222
esql.query:
@@ -211,7 +231,31 @@ Foldable query using PHRASE_MATCH on name but with non-foldable expression:
211231

212232
---
213233

234+
Foldable query using MATCH_PHRASE on name but with non constant query:
235+
- do:
236+
catch: bad_request
237+
esql.query:
238+
body:
239+
query: |
240+
FROM employees
241+
| WHERE MATCH_PHRASE(name, name)
242+
| KEEP hire_date, salary, salary_change, salary_change_long, name
243+
| LIMIT 5
244+
- match: { error.type: "verification_exception" }
245+
- contains: { error.reason: "Query must be a valid string in [MATCH_PHRASE(name, name)], found [name" }
246+
247+
---
248+
249+
214250
Foldable query using MULTI_MATCH on name:
251+
- requires:
252+
test_runner_features: [ capabilities ]
253+
capabilities:
254+
- method: POST
255+
path: /_query
256+
parameters: [ ]
257+
capabilities: [ multi_match_function ]
258+
reason: "Uses MULTI_MATCH function"
215259
- do:
216260
esql.query:
217261
body:
@@ -235,6 +279,14 @@ Foldable query using MULTI_MATCH on name:
235279
---
236280

237281
Foldable query using MULTI_MATCH on name but with non-foldable expression:
282+
- requires:
283+
test_runner_features: [ capabilities ]
284+
capabilities:
285+
- method: POST
286+
path: /_query
287+
parameters: [ ]
288+
capabilities: [ multi_match_function ]
289+
reason: "Uses MULTI_MATCH function"
238290
- do:
239291
catch: bad_request
240292
esql.query:
@@ -249,6 +301,29 @@ Foldable query using MULTI_MATCH on name but with non-foldable expression:
249301

250302
---
251303

304+
Query using MULTI_MATCH on name but with non constant query:
305+
- requires:
306+
test_runner_features: [ capabilities ]
307+
capabilities:
308+
- method: POST
309+
path: /_query
310+
parameters: [ ]
311+
capabilities: [ multi_match_function ]
312+
reason: "Uses MULTI_MATCH function"
313+
- do:
314+
catch: bad_request
315+
esql.query:
316+
body:
317+
query: |
318+
FROM employees
319+
| WHERE MULTI_MATCH(name, name)
320+
| KEEP hire_date, salary, salary_change, salary_change_long, name
321+
| LIMIT 5
322+
- match: { error.type: "verification_exception" }
323+
- contains: { error.reason: "Query must be a valid string in [MULTI_MATCH(name, name)], found [name" }
324+
325+
---
326+
252327
Foldable query using QSTR on name:
253328
- do:
254329
esql.query:
@@ -287,7 +362,30 @@ Foldable query using QSTR on name but with non-foldable expression:
287362

288363
---
289364

365+
Foldable query using KQL on name but with non-foldable expression:
366+
- do:
367+
catch: bad_request
368+
esql.query:
369+
body:
370+
query: |
371+
FROM employees
372+
| WHERE KQL(name)
373+
| KEEP hire_date, salary, salary_change, salary_change_long, name
374+
| LIMIT 5
375+
- match: { error.type: "verification_exception" }
376+
- contains: { error.reason: "Query must be a valid string in [KQL(name)], found [name" }
377+
378+
---
379+
290380
Foldable query using KNN on image_vector:
381+
- requires:
382+
test_runner_features: [ capabilities ]
383+
capabilities:
384+
- method: POST
385+
path: /_query
386+
parameters: [ ]
387+
capabilities: [ knn_function_v2 ]
388+
reason: "Uses KNN function"
291389
- do:
292390
esql.query:
293391
body:
@@ -310,6 +408,14 @@ Foldable query using KNN on image_vector:
310408
---
311409

312410
Foldable query using KNN on image_vector but with non-foldable expression:
411+
- requires:
412+
test_runner_features: [ capabilities ]
413+
capabilities:
414+
- method: POST
415+
path: /_query
416+
parameters: [ ]
417+
capabilities: [ knn_function_v2 ]
418+
reason: "Uses KNN function"
313419
- do:
314420
catch: bad_request
315421
esql.query:
@@ -321,3 +427,73 @@ Foldable query using KNN on image_vector but with non-foldable expression:
321427
| LIMIT 5
322428
- match: { error.type: "verification_exception" }
323429
- contains: { error.reason: "third argument of [KNN(image_vector, [0.4, 0.5, 0.9], 1+salary)] must be a constant, received [1+salary]" }
430+
431+
---
432+
433+
KNN on non constant k():
434+
- requires:
435+
test_runner_features: [ capabilities ]
436+
capabilities:
437+
- method: POST
438+
path: /_query
439+
parameters: [ ]
440+
capabilities: [ knn_function_v2 ]
441+
reason: "Uses KNN function"
442+
- do:
443+
catch: bad_request
444+
esql.query:
445+
body:
446+
query: |
447+
FROM employees
448+
| WHERE KNN(image_vector, [0.4, 0.5, 0.9], salary)
449+
| KEEP hire_date, salary, salary_change, salary_change_long, name, image_vector
450+
| LIMIT 5
451+
- match: { error.type: "verification_exception" }
452+
- contains: { error.reason: "third argument of [KNN(image_vector, [0.4, 0.5, 0.9], salary)] must be a constant, received [salary" }
453+
454+
---
455+
456+
KNN on non constant query:
457+
- requires:
458+
test_runner_features: [ capabilities ]
459+
capabilities:
460+
- method: POST
461+
path: /_query
462+
parameters: [ ]
463+
capabilities: [ knn_function_v2 ]
464+
reason: "Uses KNN function"
465+
- do:
466+
catch: bad_request
467+
esql.query:
468+
body:
469+
query: |
470+
FROM employees
471+
| WHERE KNN(image_vector, image_vector, 1)
472+
| KEEP hire_date, salary, salary_change, salary_change_long, name, image_vector
473+
| LIMIT 5
474+
- match: { error.type: "verification_exception" }
475+
- contains: { error.reason: "Query must be a valid string in [KNN(image_vector, image_vector, 1)], found [image_vector" }
476+
477+
---
478+
479+
Query using TERM function on name but with non constant query:
480+
- requires:
481+
test_runner_features: [ capabilities ]
482+
capabilities:
483+
- method: POST
484+
path: /_query
485+
parameters: [ ]
486+
capabilities: [ term_function ]
487+
reason: "Uses TERM function"
488+
- do:
489+
catch: bad_request
490+
esql.query:
491+
body:
492+
query: |
493+
FROM employees
494+
| WHERE TERM(name, salary)
495+
| KEEP hire_date, salary, salary_change, salary_change_long, name
496+
| LIMIT 5
497+
- match: { error.type: "verification_exception" }
498+
- contains: { error.reason: "second argument of [TERM(name, salary)] must be [string], found value [salary] type [integer]" }
499+

0 commit comments

Comments
 (0)