@@ -1357,40 +1357,45 @@ private void checkNonFieldBasedFullTextFunctionsNotAllowedAfterCommands(String f
13571357 }
13581358
13591359 public void testFullTextFunctionsOnlyAllowedInWhere () throws Exception {
1360- checkFullTextFunctionsOnlyAllowedInWhere ("MATCH" , "match(title, \" Meditation\" )" , "function" );
1361- checkFullTextFunctionsOnlyAllowedInWhere (":" , "title:\" Meditation\" " , "operator" );
1362- checkFullTextFunctionsOnlyAllowedInWhere ("QSTR" , "qstr(\" Meditation\" )" , "function" );
1363- checkFullTextFunctionsOnlyAllowedInWhere ("KQL" , "kql(\" Meditation\" )" , "function" );
1364- checkFullTextFunctionsOnlyAllowedInWhere ("MatchPhrase" , "match_phrase(title, \" Meditation\" )" , "function" );
1360+ String defaultErrorMsg = "is only supported in WHERE and STATS commands" ;
1361+ checkFullTextFunctionsOnlyAllowedInWhere ("MATCH" , "match(title, \" Meditation\" )" , "function" , defaultErrorMsg );
1362+ checkFullTextFunctionsOnlyAllowedInWhere (":" , "title:\" Meditation\" " , "operator" , defaultErrorMsg );
1363+ checkFullTextFunctionsOnlyAllowedInWhere ("QSTR" , "qstr(\" Meditation\" )" , "function" , defaultErrorMsg );
1364+ checkFullTextFunctionsOnlyAllowedInWhere ("KQL" , "kql(\" Meditation\" )" , "function" , defaultErrorMsg );
1365+ checkFullTextFunctionsOnlyAllowedInWhere ("MatchPhrase" , "match_phrase(title, \" Meditation\" )" , "function" , defaultErrorMsg );
13651366 if (EsqlCapabilities .Cap .TERM_FUNCTION .isEnabled ()) {
1366- checkFullTextFunctionsOnlyAllowedInWhere ("Term" , "term(title, \" Meditation\" )" , "function" );
1367+ checkFullTextFunctionsOnlyAllowedInWhere ("Term" , "term(title, \" Meditation\" )" , "function" , defaultErrorMsg );
13671368 }
13681369 if (EsqlCapabilities .Cap .MULTI_MATCH_FUNCTION .isEnabled ()) {
1369- checkFullTextFunctionsOnlyAllowedInWhere ("MultiMatch" , "multi_match(\" Meditation\" , title, body)" , "function" );
1370+ checkFullTextFunctionsOnlyAllowedInWhere ("MultiMatch" , "multi_match(\" Meditation\" , title, body)" , "function" , defaultErrorMsg );
13701371 }
13711372 if (EsqlCapabilities .Cap .KNN_FUNCTION .isEnabled ()) {
1372- checkFullTextFunctionsOnlyAllowedInWhere ("KNN" , "knn(vector, [0, 1, 2])" , "function" );
1373+ checkFullTextFunctionsOnlyAllowedInWhere ("KNN" , "knn(vector, [0, 1, 2])" , "function" , "is only supported in WHERE commands" );
13731374 }
13741375 }
13751376
1376- private void checkFullTextFunctionsOnlyAllowedInWhere (String functionName , String functionInvocation , String functionType )
1377- throws Exception {
1377+ private void checkFullTextFunctionsOnlyAllowedInWhere (
1378+ String functionName ,
1379+ String functionInvocation ,
1380+ String functionType ,
1381+ String errorMsg
1382+ ) throws Exception {
13781383 assertThat (
13791384 error ("from test | eval y = " + functionInvocation , fullTextAnalyzer ),
1380- containsString ("[" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands" )
1385+ containsString ("[" + functionName + "] " + functionType + " " + errorMsg )
13811386 );
13821387 assertThat (
13831388 error ("from test | sort " + functionInvocation + " asc" , fullTextAnalyzer ),
1384- containsString ("[" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands" )
1389+ containsString ("[" + functionName + "] " + functionType + " " + errorMsg )
13851390 );
13861391 assertThat (
13871392 error ("from test | stats max_id = max(id) by " + functionInvocation , fullTextAnalyzer ),
1388- containsString ("[" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands" )
1393+ containsString ("[" + functionName + "] " + functionType + " " + errorMsg )
13891394 );
13901395 if ("KQL" .equals (functionName ) || "QSTR" .equals (functionName )) {
13911396 assertThat (
13921397 error ("row a = " + functionInvocation , fullTextAnalyzer ),
1393- containsString ("[" + functionName + "] " + functionType + " is only supported in WHERE and STATS commands" )
1398+ containsString ("[" + functionName + "] " + functionType + " " + errorMsg )
13941399 );
13951400 }
13961401 }
@@ -2215,7 +2220,7 @@ public void testFullTextFunctionsInStats() {
22152220 checkFullTextFunctionsInStats ("multi_match(\" Meditation\" , title, body)" );
22162221 }
22172222 if (EsqlCapabilities .Cap .KNN_FUNCTION .isEnabled ()) {
2218- checkFullTextFunctionsInStats ("knn(vector, [0, 1, 2])" );
2223+ checkFullTextFunctionsInStatsError ("knn(vector, [0, 1, 2])" );
22192224 }
22202225 }
22212226
@@ -2234,6 +2239,25 @@ private void checkFullTextFunctionsInStats(String functionInvocation) {
22342239 );
22352240 }
22362241
2242+ private void checkFullTextFunctionsInStatsError (String functionInvocation ) {
2243+ assertThat (
2244+ error ("from test metadata _score | stats c = max(_score) where " + functionInvocation , fullTextAnalyzer ),
2245+ containsString ("cannot use _score aggregations with a WHERE filter in a STATS command" )
2246+ );
2247+ assertThat (
2248+ error ("from test | stats c = max(id) where " + functionInvocation , fullTextAnalyzer ),
2249+ containsString ("is only supported in WHERE commands" )
2250+ );
2251+ assertThat (
2252+ error ("from test | stats c = max(id) where " + functionInvocation + " or length(title) > 10" , fullTextAnalyzer ),
2253+ containsString ("is only supported in WHERE commands" )
2254+ );
2255+ assertThat (
2256+ error ("from test metadata _score | stats c = max(_score) where " + functionInvocation , fullTextAnalyzer ),
2257+ containsString ("is only supported in WHERE commands" )
2258+ );
2259+ }
2260+
22372261 private void query (String query ) {
22382262 query (query , defaultAnalyzer );
22392263 }
0 commit comments