@@ -1341,27 +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" );
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+ }
13651355 }
13661356
13671357 private void checkFullTextFunctionsOnlyAllowedInWhere (String functionName , String functionInvocation , String functionType )
@@ -1378,6 +1368,12 @@ private void checkFullTextFunctionsOnlyAllowedInWhere(String functionName, Strin
13781368 "1:47: [" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands" ,
13791369 error ("from test | stats max_salary = max(salary) by " + functionInvocation )
13801370 );
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+ }
13811377 }
13821378
13831379 public void testQueryStringFunctionArgNotNullOrConstant () throws Exception {
@@ -1398,29 +1394,6 @@ public void testKqlFunctionArgNotNullOrConstant() throws Exception {
13981394 // Other value types are tested in KqlFunctionTests
13991395 }
14001396
1401- public void testFullTextFunctionsWithDisjunctions () {
1402- checkWithDisjunctions ("MATCH" , "match(first_name, \" Anna\" )" , "function" );
1403- checkWithDisjunctions (":" , "first_name : \" Anna\" " , "operator" );
1404- checkWithDisjunctions ("QSTR" , "qstr(\" first_name: Anna\" )" , "function" );
1405- checkWithDisjunctions ("KQL" , "kql(\" first_name: Anna\" )" , "function" );
1406- if (EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ()) {
1407- checkWithDisjunctions ("Term" , "term(first_name, \" Anna\" )" , "function" );
1408- }
1409- if (EsqlCapabilities .Cap .MULTI_MATCH_FUNCTION .isEnabled ()) {
1410- checkWithDisjunctions ("MultiMatch" , "multi_match(\" Anna\" , first_name)" , "function" );
1411- }
1412- }
1413-
1414- private void checkWithDisjunctions (String functionName , String functionInvocation , String functionType ) {
1415- query ("from test | where " + functionInvocation + " or length(first_name) > 12" );
1416- query (
1417- "from test | where ("
1418- + functionInvocation
1419- + " or first_name is not null) or (length(first_name) > 12 and match(last_name, \" Smith\" ))"
1420- );
1421- query ("from test | where " + functionInvocation + " or (last_name is not null and first_name is null)" );
1422- }
1423-
14241397 public void testFullTextFunctionsDisjunctions () {
14251398 checkWithFullTextFunctionsDisjunctions ("match(last_name, \" Smith\" )" );
14261399 checkWithFullTextFunctionsDisjunctions ("multi_match(\" Smith\" , first_name, last_name)" );
@@ -1472,25 +1445,20 @@ private void checkWithFullTextFunctionsDisjunctions(String functionInvocation) {
14721445
14731446 }
14741447
1475- public void testQueryStringFunctionWithNonBooleanFunctions () {
1476- checkFullTextFunctionsWithNonBooleanFunctions ("QSTR" , "qstr(\" first_name: Anna\" )" , "function" );
1477- }
1478-
1479- public void testKqlFunctionWithNonBooleanFunctions () {
1480- checkFullTextFunctionsWithNonBooleanFunctions ("KQL" , "kql(\" first_name: Anna\" )" , "function" );
1481- }
1482-
1483- public void testMatchFunctionWithNonBooleanFunctions () {
1448+ public void testFullTextFunctionsWithNonBooleanFunctions () {
14841449 checkFullTextFunctionsWithNonBooleanFunctions ("MATCH" , "match(first_name, \" Anna\" )" , "function" );
1485- }
1486-
1487- public void testTermFunctionWithNonBooleanFunctions () {
1488- assumeTrue ("term function capability not available" , EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ());
1489- checkFullTextFunctionsWithNonBooleanFunctions ("Term" , "term(first_name, \" Anna\" )" , "function" );
1490- }
1491-
1492- public void testMatchOperatorWithNonBooleanFunctions () {
14931450 checkFullTextFunctionsWithNonBooleanFunctions (":" , "first_name:\" Anna\" " , "operator" );
1451+ checkFullTextFunctionsWithNonBooleanFunctions ("QSTR" , "qstr(\" first_name: Anna\" )" , "function" );
1452+ checkFullTextFunctionsWithNonBooleanFunctions ("KQL" , "kql(\" first_name: Anna\" )" , "function" );
1453+ if (EsqlCapabilities .Cap .MULTI_MATCH_FUNCTION .isEnabled ()) {
1454+ checkFullTextFunctionsWithNonBooleanFunctions ("MultiMatch" , "multi_match(\" Anna\" , first_name, last_name)" , "function" );
1455+ }
1456+ if (EsqlCapabilities .Cap .KNN_FUNCTION .isEnabled ()) {
1457+ checkFullTextFunctionsWithNonBooleanFunctions ("KNN" , "knn(vector, [1, 2, 3])" , "function" );
1458+ }
1459+ if (EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ()) {
1460+ checkFullTextFunctionsWithNonBooleanFunctions ("Term" , "term(first_name, \" Anna\" )" , "function" );
1461+ }
14941462 }
14951463
14961464 private void checkFullTextFunctionsWithNonBooleanFunctions (String functionName , String functionInvocation , String functionType ) {
@@ -1561,18 +1529,6 @@ public void testMatchFunctionArgNotConstant() throws Exception {
15611529 // Other value types are tested in QueryStringFunctionTests
15621530 }
15631531
1564- // These should pass eventually once we lift some restrictions on match function
1565- public void testMatchFunctionCurrentlyUnsupportedBehaviour () throws Exception {
1566- assertEquals (
1567- "1:68: Unknown column [first_name]" ,
1568- error ("from test | stats max_salary = max(salary) by emp_no | where match(first_name, \" Anna\" )" )
1569- );
1570- assertEquals (
1571- "1:62: Unknown column [first_name]" ,
1572- error ("from test | stats max_salary = max(salary) by emp_no | where first_name : \" Anna\" " )
1573- );
1574- }
1575-
15761532 public void testMatchFunctionNullArgs () throws Exception {
15771533 assertEquals (
15781534 "1:19: first argument of [match(null, \" query\" )] cannot be null, received [null]" ,
@@ -1602,15 +1558,6 @@ public void testTermFunctionArgNotConstant() throws Exception {
16021558 // Other value types are tested in QueryStringFunctionTests
16031559 }
16041560
1605- // These should pass eventually once we lift some restrictions on match function
1606- public void testTermFunctionCurrentlyUnsupportedBehaviour () throws Exception {
1607- assumeTrue ("term function capability not available" , EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ());
1608- assertEquals (
1609- "1:67: Unknown column [first_name]" ,
1610- error ("from test | stats max_salary = max(salary) by emp_no | where term(first_name, \" Anna\" )" )
1611- );
1612- }
1613-
16141561 public void testTermFunctionNullArgs () throws Exception {
16151562 assumeTrue ("term function capability not available" , EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ());
16161563 assertEquals (
@@ -2140,16 +2087,15 @@ public void testLookupJoinDataTypeMismatch() {
21402087 );
21412088 }
21422089
2143- public void testMatchOptions () {
2090+ public void testFullTextFunctionOptions () {
21442091 checkOptionDataTypes (Match .ALLOWED_OPTIONS , "FROM test | WHERE match(first_name, \" Jean\" , {\" %s\" : %s})" );
2145- }
2146-
2147- public void testMultiMatchOptions () {
2148- checkOptionDataTypes (MultiMatch .OPTIONS , "FROM test | WHERE MULTI_MATCH(\" Jean\" , first_name, last_name, {\" %s\" : %s})" );
2149- }
2150-
2151- public void testQueryStringOptions () {
21522092 checkOptionDataTypes (QueryString .ALLOWED_OPTIONS , "FROM test | WHERE QSTR(\" first_name: Jean\" , {\" %s\" : %s})" );
2093+ if (EsqlCapabilities .Cap .MULTI_MATCH_FUNCTION .isEnabled ()){
2094+ checkOptionDataTypes (MultiMatch .OPTIONS , "FROM test | WHERE MULTI_MATCH(\" Jean\" , first_name, last_name, {\" %s\" : %s})" );
2095+ }
2096+ if (EsqlCapabilities .Cap .KNN_FUNCTION .isEnabled ()) {
2097+ checkOptionDataTypes (Knn .ALLOWED_OPTIONS , "FROM test | WHERE KNN(vector, [0.1, 0.2, 0.3], {\" %s\" : %s})" );
2098+ }
21532099 }
21542100
21552101 /**
@@ -2200,39 +2146,6 @@ private static String exampleValueForType(DataType currentType) {
22002146 };
22012147 }
22022148
2203- public void testMultiMatchFunctionIsNotNullable () {
2204- assertEquals (
2205- "1:62: [MultiMatch] function cannot operate on [text::keyword], which is not a field from an index mapping" ,
2206- error ("row n = null | eval text = n + 5 | where multi_match(\" Anna\" , text::keyword)" )
2207- );
2208- }
2209-
2210- public void testMultiMatchWithNonIndexedColumnCurrentlyUnsupported () {
2211- assertEquals (
2212- "1:78: [MultiMatch] function cannot operate on [initial], which is not a field from an index mapping" ,
2213- error ("from test | eval initial = substring(first_name, 1) | where multi_match(\" A\" , initial)" )
2214- );
2215- assertEquals (
2216- "1:80: [MultiMatch] function cannot operate on [text], which is not a field from an index mapping" ,
2217- error ("from test | eval text=concat(first_name, last_name) | where multi_match(\" cat\" , text)" )
2218- );
2219- }
2220-
2221- public void testMultiMatchFunctionNotAllowedAfterCommands () throws Exception {
2222- assertEquals (
2223- "1:24: [MultiMatch] function cannot be used after LIMIT" ,
2224- error ("from test | limit 10 | where multi_match(\" Anna\" , first_name)" )
2225- );
2226- assertEquals (
2227- "1:47: [MultiMatch] function cannot be used after STATS" ,
2228- error ("from test | STATS c = AVG(salary) BY gender | where multi_match(\" F\" , gender)" )
2229- );
2230- }
2231-
2232- public void testMultiMatchFunctionWithNonBooleanFunctions () {
2233- checkFullTextFunctionsWithNonBooleanFunctions ("MultiMatch" , "multi_match(\" Anna\" , first_name, last_name)" , "function" );
2234- }
2235-
22362149 public void testMultiMatchFunctionArgNotConstant () throws Exception {
22372150 assertEquals (
22382151 "1:19: second argument of [match(first_name, first_name)] must be a constant, received [first_name]" ,
@@ -2242,14 +2155,24 @@ public void testMultiMatchFunctionArgNotConstant() throws Exception {
22422155 "1:59: second argument of [match(first_name, query)] must be a constant, received [query]" ,
22432156 error ("from test | eval query = concat(\" first\" , \" name\" ) | where match(first_name, query)" )
22442157 );
2245- // Other value types are tested in QueryStringFunctionTests
22462158 }
22472159
2248- // Should pass eventually once we lift some restrictions on the multi-match function .
2160+ // Should pass eventually once we lift some restrictions on full text search functions .
22492161 public void testMultiMatchFunctionCurrentlyUnsupportedBehaviour () throws Exception {
2250- assertEquals (
2251- "1:82: Unknown column [first_name]\n line 1:94: Unknown column [last_name]" ,
2252- error ("from test | stats max_salary = max(salary) by emp_no | where multi_match(\" Anna\" , first_name, last_name)" )
2162+ testFullTextFunctionsCurrentlyUnsupportedBehaviour ("match(first_name, \" Anna\" )" );
2163+ testFullTextFunctionsCurrentlyUnsupportedBehaviour ("first_name : \" Anna\" " );
2164+ if (EsqlCapabilities .Cap .MULTI_MATCH_FUNCTION .isEnabled ()) {
2165+ testFullTextFunctionsCurrentlyUnsupportedBehaviour ("multi_match(\" Anna\" , first_name)" );
2166+ }
2167+ if (EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ()) {
2168+ testFullTextFunctionsCurrentlyUnsupportedBehaviour ("term(first_name, \" Anna\" )" );
2169+ }
2170+ }
2171+
2172+ private void testFullTextFunctionsCurrentlyUnsupportedBehaviour (String functionInvocation ) throws Exception {
2173+ assertThat (
2174+ error ("from test | stats max_salary = max(salary) by emp_no | where " + functionInvocation ),
2175+ containsString ("Unknown column [first_name]" )
22532176 );
22542177 }
22552178
0 commit comments