Skip to content

Commit 6ea4995

Browse files
committed
Simplify tests
1 parent fbe8b6c commit 6ea4995

File tree

1 file changed

+49
-112
lines changed

1 file changed

+49
-112
lines changed

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

Lines changed: 49 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,31 +1341,17 @@ public void testNonFieldBasedFullTextFunctionsNotAllowedAfterCommands(String fun
13411341
);
13421342
}
13431343

1344-
public void testQueryStringFunctionOnlyAllowedInWhere() throws Exception {
1345-
assertEquals("1:9: [QSTR] function is only supported in WHERE and STATS commands", error("row a = qstr(\"Anna\")"));
1346-
checkFullTextFunctionsOnlyAllowedInWhere("QSTR", "qstr(\"Anna\")", "function");
1347-
}
1348-
1349-
public void testKqlFunctionOnlyAllowedInWhere() throws Exception {
1350-
assertEquals("1:9: [KQL] function is only supported in WHERE and STATS commands", error("row a = kql(\"Anna\")"));
1351-
checkFullTextFunctionsOnlyAllowedInWhere("KQL", "kql(\"Anna\")", "function");
1352-
}
1353-
1354-
public void testMatchFunctionOnlyAllowedInWhere() throws Exception {
1344+
public void testFullTextFunctionsOnlyAllowedInWhere() throws Exception {
13551345
checkFullTextFunctionsOnlyAllowedInWhere("MATCH", "match(first_name, \"Anna\")", "function");
1356-
}
1357-
1358-
public void testTermFunctionOnlyAllowedInWhere() throws Exception {
1359-
assumeTrue("term function capability not available", EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled());
1360-
checkFullTextFunctionsOnlyAllowedInWhere("Term", "term(first_name, \"Anna\")", "function");
1361-
}
1362-
1363-
public void testMatchOperatornOnlyAllowedInWhere() throws Exception {
13641346
checkFullTextFunctionsOnlyAllowedInWhere(":", "first_name:\"Anna\"", "operator");
1365-
}
1366-
1367-
public void testKnnFunctionOnlyAllowedInWhere() throws Exception {
1368-
checkFullTextFunctionsOnlyAllowedInWhere("KNN", "knn(vector, [1, 2, 3])", "function");
1347+
checkFullTextFunctionsOnlyAllowedInWhere("QSTR", "qstr(\"Anna\")", "function");
1348+
checkFullTextFunctionsOnlyAllowedInWhere("KQL", "kql(\"Anna\")", "function");
1349+
if (EsqlCapabilities.Cap.KNN_FUNCTION.isEnabled()) {
1350+
checkFullTextFunctionsOnlyAllowedInWhere("KNN", "knn(vector, [1, 2, 3])", "function");
1351+
}
1352+
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {
1353+
checkFullTextFunctionsOnlyAllowedInWhere("Term", "term(first_name, \"Anna\")", "function");
1354+
}
13691355
}
13701356

13711357
private void checkFullTextFunctionsOnlyAllowedInWhere(String functionName, String functionInvocation, String functionType)
@@ -1382,6 +1368,12 @@ private void checkFullTextFunctionsOnlyAllowedInWhere(String functionName, Strin
13821368
"1:47: [" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands",
13831369
error("from test | stats max_salary = max(salary) by " + functionInvocation)
13841370
);
1371+
if( "KQL".equals(functionName) || "QSTR".equals(functionName)) {
1372+
assertEquals(
1373+
"1:9: [" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands",
1374+
error("row a = " + functionInvocation)
1375+
);
1376+
}
13851377
}
13861378

13871379
public void testQueryStringFunctionArgNotNullOrConstant() throws Exception {
@@ -1456,25 +1448,20 @@ private void checkWithFullTextFunctionsDisjunctions(String functionInvocation) {
14561448

14571449
}
14581450

1459-
public void testQueryStringFunctionWithNonBooleanFunctions() {
1460-
checkFullTextFunctionsWithNonBooleanFunctions("QSTR", "qstr(\"first_name: Anna\")", "function");
1461-
}
1462-
1463-
public void testKqlFunctionWithNonBooleanFunctions() {
1464-
checkFullTextFunctionsWithNonBooleanFunctions("KQL", "kql(\"first_name: Anna\")", "function");
1465-
}
1466-
1467-
public void testMatchFunctionWithNonBooleanFunctions() {
1451+
public void testFullTextFunctionsWithNonBooleanFunctions() {
14681452
checkFullTextFunctionsWithNonBooleanFunctions("MATCH", "match(first_name, \"Anna\")", "function");
1469-
}
1470-
1471-
public void testTermFunctionWithNonBooleanFunctions() {
1472-
assumeTrue("term function capability not available", EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled());
1473-
checkFullTextFunctionsWithNonBooleanFunctions("Term", "term(first_name, \"Anna\")", "function");
1474-
}
1475-
1476-
public void testMatchOperatorWithNonBooleanFunctions() {
14771453
checkFullTextFunctionsWithNonBooleanFunctions(":", "first_name:\"Anna\"", "operator");
1454+
checkFullTextFunctionsWithNonBooleanFunctions("QSTR", "qstr(\"first_name: Anna\")", "function");
1455+
checkFullTextFunctionsWithNonBooleanFunctions("KQL", "kql(\"first_name: Anna\")", "function");
1456+
if (EsqlCapabilities.Cap.MULTI_MATCH_FUNCTION.isEnabled()) {
1457+
checkFullTextFunctionsWithNonBooleanFunctions("MultiMatch", "multi_match(\"Anna\", first_name, last_name)", "function");
1458+
}
1459+
if (EsqlCapabilities.Cap.KNN_FUNCTION.isEnabled()) {
1460+
checkFullTextFunctionsWithNonBooleanFunctions("KNN", "knn(vector, [1, 2, 3])", "function");
1461+
}
1462+
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {
1463+
checkFullTextFunctionsWithNonBooleanFunctions("Term", "term(first_name, \"Anna\")", "function");
1464+
}
14781465
}
14791466

14801467
private void checkFullTextFunctionsWithNonBooleanFunctions(String functionName, String functionInvocation, String functionType) {
@@ -1545,18 +1532,6 @@ public void testMatchFunctionArgNotConstant() throws Exception {
15451532
// Other value types are tested in QueryStringFunctionTests
15461533
}
15471534

1548-
// These should pass eventually once we lift some restrictions on match function
1549-
public void testMatchFunctionCurrentlyUnsupportedBehaviour() throws Exception {
1550-
assertEquals(
1551-
"1:68: Unknown column [first_name]",
1552-
error("from test | stats max_salary = max(salary) by emp_no | where match(first_name, \"Anna\")")
1553-
);
1554-
assertEquals(
1555-
"1:62: Unknown column [first_name]",
1556-
error("from test | stats max_salary = max(salary) by emp_no | where first_name : \"Anna\"")
1557-
);
1558-
}
1559-
15601535
public void testMatchFunctionNullArgs() throws Exception {
15611536
assertEquals(
15621537
"1:19: first argument of [match(null, \"query\")] cannot be null, received [null]",
@@ -1586,15 +1561,6 @@ public void testTermFunctionArgNotConstant() throws Exception {
15861561
// Other value types are tested in QueryStringFunctionTests
15871562
}
15881563

1589-
// These should pass eventually once we lift some restrictions on match function
1590-
public void testTermFunctionCurrentlyUnsupportedBehaviour() throws Exception {
1591-
assumeTrue("term function capability not available", EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled());
1592-
assertEquals(
1593-
"1:67: Unknown column [first_name]",
1594-
error("from test | stats max_salary = max(salary) by emp_no | where term(first_name, \"Anna\")")
1595-
);
1596-
}
1597-
15981564
public void testTermFunctionNullArgs() throws Exception {
15991565
assumeTrue("term function capability not available", EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled());
16001566
assertEquals(
@@ -2124,21 +2090,15 @@ public void testLookupJoinDataTypeMismatch() {
21242090
);
21252091
}
21262092

2127-
public void testMatchOptions() {
2093+
public void testFullTextFunctionOptions() {
21282094
checkOptionDataTypes(Match.ALLOWED_OPTIONS, "FROM test | WHERE match(first_name, \"Jean\", {\"%s\": %s})");
2129-
}
2130-
2131-
public void testMultiMatchOptions() {
2132-
checkOptionDataTypes(MultiMatch.OPTIONS, "FROM test | WHERE MULTI_MATCH(\"Jean\", first_name, last_name, {\"%s\": %s})");
2133-
}
2134-
2135-
public void testQueryStringOptions() {
21362095
checkOptionDataTypes(QueryString.ALLOWED_OPTIONS, "FROM test | WHERE QSTR(\"first_name: Jean\", {\"%s\": %s})");
2137-
}
2138-
2139-
public void testKnnOptions() {
2140-
assumeTrue("knn must be enabled", EsqlCapabilities.Cap.KNN_FUNCTION.isEnabled());
2141-
checkOptionDataTypes(Knn.ALLOWED_OPTIONS, "FROM test | WHERE KNN(vector, [0.1, 0.2, 0.3], {\"%s\": %s})");
2096+
if (EsqlCapabilities.Cap.MULTI_MATCH_FUNCTION.isEnabled()){
2097+
checkOptionDataTypes(MultiMatch.OPTIONS, "FROM test | WHERE MULTI_MATCH(\"Jean\", first_name, last_name, {\"%s\": %s})");
2098+
}
2099+
if (EsqlCapabilities.Cap.KNN_FUNCTION.isEnabled()) {
2100+
checkOptionDataTypes(Knn.ALLOWED_OPTIONS, "FROM test | WHERE KNN(vector, [0.1, 0.2, 0.3], {\"%s\": %s})");
2101+
}
21422102
}
21432103

21442104
/**
@@ -2189,39 +2149,6 @@ private static String exampleValueForType(DataType currentType) {
21892149
};
21902150
}
21912151

2192-
public void testMultiMatchFunctionIsNotNullable() {
2193-
assertEquals(
2194-
"1:62: [MultiMatch] function cannot operate on [text::keyword], which is not a field from an index mapping",
2195-
error("row n = null | eval text = n + 5 | where multi_match(\"Anna\", text::keyword)")
2196-
);
2197-
}
2198-
2199-
public void testMultiMatchWithNonIndexedColumnCurrentlyUnsupported() {
2200-
assertEquals(
2201-
"1:78: [MultiMatch] function cannot operate on [initial], which is not a field from an index mapping",
2202-
error("from test | eval initial = substring(first_name, 1) | where multi_match(\"A\", initial)")
2203-
);
2204-
assertEquals(
2205-
"1:80: [MultiMatch] function cannot operate on [text], which is not a field from an index mapping",
2206-
error("from test | eval text=concat(first_name, last_name) | where multi_match(\"cat\", text)")
2207-
);
2208-
}
2209-
2210-
public void testMultiMatchFunctionNotAllowedAfterCommands() throws Exception {
2211-
assertEquals(
2212-
"1:24: [MultiMatch] function cannot be used after LIMIT",
2213-
error("from test | limit 10 | where multi_match(\"Anna\", first_name)")
2214-
);
2215-
assertEquals(
2216-
"1:47: [MultiMatch] function cannot be used after STATS",
2217-
error("from test | STATS c = AVG(salary) BY gender | where multi_match(\"F\", gender)")
2218-
);
2219-
}
2220-
2221-
public void testMultiMatchFunctionWithNonBooleanFunctions() {
2222-
checkFullTextFunctionsWithNonBooleanFunctions("MultiMatch", "multi_match(\"Anna\", first_name, last_name)", "function");
2223-
}
2224-
22252152
public void testMultiMatchFunctionArgNotConstant() throws Exception {
22262153
assertEquals(
22272154
"1:19: second argument of [match(first_name, first_name)] must be a constant, received [first_name]",
@@ -2231,14 +2158,24 @@ public void testMultiMatchFunctionArgNotConstant() throws Exception {
22312158
"1:59: second argument of [match(first_name, query)] must be a constant, received [query]",
22322159
error("from test | eval query = concat(\"first\", \" name\") | where match(first_name, query)")
22332160
);
2234-
// Other value types are tested in QueryStringFunctionTests
22352161
}
22362162

2237-
// Should pass eventually once we lift some restrictions on the multi-match function.
2163+
// Should pass eventually once we lift some restrictions on full text search functions.
22382164
public void testMultiMatchFunctionCurrentlyUnsupportedBehaviour() throws Exception {
2239-
assertEquals(
2240-
"1:82: Unknown column [first_name]\nline 1:94: Unknown column [last_name]",
2241-
error("from test | stats max_salary = max(salary) by emp_no | where multi_match(\"Anna\", first_name, last_name)")
2165+
testFullTextFunctionsCurrentlyUnsupportedBehaviour("match(first_name, \"Anna\")");
2166+
testFullTextFunctionsCurrentlyUnsupportedBehaviour("first_name : \"Anna\"");
2167+
if (EsqlCapabilities.Cap.MULTI_MATCH_FUNCTION.isEnabled()) {
2168+
testFullTextFunctionsCurrentlyUnsupportedBehaviour("multi_match(\"Anna\", first_name)");
2169+
}
2170+
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {
2171+
testFullTextFunctionsCurrentlyUnsupportedBehaviour("term(first_name, \"Anna\")");
2172+
}
2173+
}
2174+
2175+
private void testFullTextFunctionsCurrentlyUnsupportedBehaviour(String functionInvocation) throws Exception {
2176+
assertThat(
2177+
error("from test | stats max_salary = max(salary) by emp_no | where " + functionInvocation),
2178+
containsString("Unknown column [first_name]")
22422179
);
22432180
}
22442181

0 commit comments

Comments
 (0)