Skip to content

Commit 34968ad

Browse files
committed
Add verifier tests
1 parent f756e85 commit 34968ad

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ required_capability: dense_vector_field_type
3535
FROM dense_vector
3636
| EVAL v = vector
3737
| RENAME v AS new_vector
38-
| DROP vector
38+
| DROP vector, first_name, last_name
3939
| SORT id
4040
;
4141

x-pack/plugin/esql/qa/testFixtures/src/main/resources/mapping-dense_vector.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"id": {
44
"type": "long"
55
},
6+
"first_name": {
7+
"type": "text"
8+
},
9+
"last_name": {
10+
"type": "text"
11+
},
612
"vector": {
713
"type": "dense_vector",
814
"similarity": "l2_norm"

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,27 +1426,27 @@ public void testKqlFunctionArgNotNullOrConstant() throws Exception {
14261426
}
14271427

14281428
public void testQueryStringWithDisjunctions() {
1429-
checkWithDisjunctions("QSTR", "qstr(\"first_name: Anna\")", "function");
1429+
checkWithDisjunctions("qstr(\"first_name: Anna\")");
14301430
}
14311431

14321432
public void testKqlFunctionWithDisjunctions() {
1433-
checkWithDisjunctions("KQL", "kql(\"first_name: Anna\")", "function");
1433+
checkWithDisjunctions("kql(\"first_name: Anna\")");
14341434
}
14351435

14361436
public void testMatchFunctionWithDisjunctions() {
1437-
checkWithDisjunctions("MATCH", "match(first_name, \"Anna\")", "function");
1437+
checkWithDisjunctions("match(first_name, \"Anna\")");
14381438
}
14391439

14401440
public void testTermFunctionWithDisjunctions() {
14411441
assumeTrue("term function capability not available", EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled());
1442-
checkWithDisjunctions("Term", "term(first_name, \"Anna\")", "function");
1442+
checkWithDisjunctions("term(first_name, \"Anna\")");
14431443
}
14441444

14451445
public void testMatchOperatorWithDisjunctions() {
1446-
checkWithDisjunctions(":", "first_name : \"Anna\"", "operator");
1446+
checkWithDisjunctions("first_name : \"Anna\"");
14471447
}
14481448

1449-
private void checkWithDisjunctions(String functionName, String functionInvocation, String functionType) {
1449+
private void checkWithDisjunctions(String functionInvocation) {
14501450
query("from test | where " + functionInvocation + " or length(first_name) > 12");
14511451
query(
14521452
"from test | where ("
@@ -1457,50 +1457,52 @@ private void checkWithDisjunctions(String functionName, String functionInvocatio
14571457
}
14581458

14591459
public void testFullTextFunctionsDisjunctions() {
1460-
checkWithFullTextFunctionsDisjunctions("match(last_name, \"Smith\")");
1461-
checkWithFullTextFunctionsDisjunctions("multi_match(\"Smith\", first_name, last_name)");
1462-
checkWithFullTextFunctionsDisjunctions("last_name : \"Smith\"");
1463-
checkWithFullTextFunctionsDisjunctions("qstr(\"last_name: Smith\")");
1464-
checkWithFullTextFunctionsDisjunctions("kql(\"last_name: Smith\")");
1460+
checkWithFullTextFunctionsDisjunctions("match(last_name, \"Smith\")", defaultAnalyzer);
1461+
checkWithFullTextFunctionsDisjunctions("multi_match(\"Smith\", first_name, last_name)", defaultAnalyzer);
1462+
checkWithFullTextFunctionsDisjunctions("last_name : \"Smith\"", defaultAnalyzer);
1463+
checkWithFullTextFunctionsDisjunctions("qstr(\"last_name: Smith\")", defaultAnalyzer);
1464+
checkWithFullTextFunctionsDisjunctions("kql(\"last_name: Smith\")", defaultAnalyzer);
1465+
Analyzer analyzer = AnalyzerTestUtils.analyzer(loadMapping("mapping-dense_vector.json", "test"));
1466+
checkWithFullTextFunctionsDisjunctions("knn(vector, [1, 2, 3])", analyzer);
14651467
}
14661468

1467-
private void checkWithFullTextFunctionsDisjunctions(String functionInvocation) {
1469+
private void checkWithFullTextFunctionsDisjunctions(String functionInvocation, Analyzer analyzer) {
14681470

14691471
// Disjunctions with non-pushable functions - scoring
1470-
query("from test | where " + functionInvocation + " or length(first_name) > 10");
1471-
query("from test | where match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)");
1472+
query("from test | where " + functionInvocation + " or length(first_name) > 10", analyzer);
1473+
query("from test | where match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)", analyzer);
14721474
query(
14731475
"from test | where ("
14741476
+ functionInvocation
14751477
+ " and length(first_name) > 0) or (match(last_name, \"Anneke\") and length(first_name) > 10)"
1476-
);
1478+
, analyzer);
14771479

14781480
// Disjunctions with non-pushable functions - no scoring
1479-
query("from test | where " + functionInvocation + " or length(first_name) > 10");
1480-
query("from test | where match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)");
1481+
query("from test | where " + functionInvocation + " or length(first_name) > 10", analyzer);
1482+
query("from test | where match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)", analyzer);
14811483
query(
14821484
"from test | where ("
14831485
+ functionInvocation
14841486
+ " and length(first_name) > 0) or (match(last_name, \"Anneke\") and length(first_name) > 10)"
1485-
);
1487+
, analyzer);
14861488

14871489
// Disjunctions with full text functions - no scoring
1488-
query("from test | where " + functionInvocation + " or match(first_name, \"Anna\")");
1489-
query("from test | where " + functionInvocation + " or not match(first_name, \"Anna\")");
1490-
query("from test | where (" + functionInvocation + " or match(first_name, \"Anna\")) and length(first_name) > 10");
1491-
query("from test | where (" + functionInvocation + " or match(first_name, \"Anna\")) and match(last_name, \"Smith\")");
1492-
query("from test | where " + functionInvocation + " or (match(first_name, \"Anna\") and match(last_name, \"Smith\"))");
1490+
query("from test | where " + functionInvocation + " or match(first_name, \"Anna\")", analyzer);
1491+
query("from test | where " + functionInvocation + " or not match(first_name, \"Anna\")", analyzer);
1492+
query("from test | where (" + functionInvocation + " or match(first_name, \"Anna\")) and length(first_name) > 10", analyzer);
1493+
query("from test | where (" + functionInvocation + " or match(first_name, \"Anna\")) and match(last_name, \"Smith\")", analyzer);
1494+
query("from test | where " + functionInvocation + " or (match(first_name, \"Anna\") and match(last_name, \"Smith\"))", analyzer);
14931495

14941496
// Disjunctions with full text functions - scoring
1495-
query("from test metadata _score | where " + functionInvocation + " or match(first_name, \"Anna\")");
1496-
query("from test metadata _score | where " + functionInvocation + " or not match(first_name, \"Anna\")");
1497-
query("from test metadata _score | where (" + functionInvocation + " or match(first_name, \"Anna\")) and length(first_name) > 10");
1497+
query("from test metadata _score | where " + functionInvocation + " or match(first_name, \"Anna\")", analyzer);
1498+
query("from test metadata _score | where " + functionInvocation + " or not match(first_name, \"Anna\")", analyzer);
1499+
query("from test metadata _score | where (" + functionInvocation + " or match(first_name, \"Anna\")) and length(first_name) > 10", analyzer);
14981500
query(
14991501
"from test metadata _score | where (" + functionInvocation + " or match(first_name, \"Anna\")) and match(last_name, \"Smith\")"
1500-
);
1502+
, analyzer);
15011503
query(
15021504
"from test metadata _score | where " + functionInvocation + " or (match(first_name, \"Anna\") and match(last_name, \"Smith\"))"
1503-
);
1505+
, analyzer);
15041506

15051507
}
15061508

@@ -2271,7 +2273,7 @@ public void testMultiMatchFunctionNotAllowedAfterCommands() throws Exception {
22712273
}
22722274

22732275
public void testMultiMatchFunctionWithDisjunctions() {
2274-
checkWithDisjunctions("MultiMatch", "multi_match(\"Anna\", first_name, last_name)", "function");
2276+
checkWithDisjunctions("multi_match(\"Anna\", first_name, last_name)");
22752277
}
22762278

22772279
public void testMultiMatchFunctionWithNonBooleanFunctions() {

0 commit comments

Comments
 (0)