@@ -1215,44 +1215,37 @@ public void testMatchInsideEval() throws Exception {
12151215 );
12161216 }
12171217
1218- public void testMatchFunctionNotAllowedAfterCommands () throws Exception {
1219- assertEquals (
1220- "1:24: [MATCH] function cannot be used after LIMIT" ,
1221- error ( "from test | limit 10 | where match(first_name, \" Anna \" )" )
1222- );
1223- assertEquals (
1224- "1:47: [MATCH] function cannot be used after STATS" ,
1225- error ( "from test | STATS c = AVG(salary) BY gender | where match(gender, \" F \" )" )
1226- );
1218+ public void testFieldBasedFullTextFunctions () throws Exception {
1219+ testFieldBasedWithNonIndexedColumn ( "MATCH" , "match(text, \" cat \" )" , "function" );
1220+ testFieldBasedWithNonIndexedColumn ( ":" , "text : \" cat \" " , "operator" );
1221+ testFieldBasedWithNonIndexedColumn ( "MultiMatch" , "multi_match( \" cat \" , text)" , "function" );
1222+
1223+ testFieldBasedFunctionNotAllowedAfterCommands ( "MATCH" , "function" , "match(first_name, \" Anna \" )" );
1224+ testFieldBasedFunctionNotAllowedAfterCommands ( ":" , "operator" , "first_name : \" Anna \" " );
1225+ testFieldBasedFunctionNotAllowedAfterCommands ( "MultiMatch" , "function" , "multi_match( \" Anna \" , first_name )" );
1226+ testFieldBasedFunctionNotAllowedAfterCommands ( "KNN" , "function" , "knn(vector, [1, 2, 3])" );
12271227 }
12281228
1229- public void testMatchFunctionAndOperatorHaveCorrectErrorMessages ( ) throws Exception {
1230- assertEquals (
1231- "1:24: [MATCH] function cannot be used after LIMIT" ,
1232- error ( "from test | limit 10 | where match(first_name, \" Anna \" ) " )
1229+ public void testFieldBasedFunctionNotAllowedAfterCommands ( String functionName , String functionType , String functionInvocation ) throws Exception {
1230+ assertThat (
1231+ error ( "from test | limit 10 | where " + functionInvocation ) ,
1232+ containsString ( "[" + functionName + "] " + functionType + " cannot be used after LIMIT " )
12331233 );
1234- assertEquals (
1235- "1:24: [MATCH] function cannot be used after LIMIT" ,
1236- error ("from test | limit 10 | where match ( first_name, \" Anna\" ) " )
1234+ String fieldName = "KNN" .equals (functionName ) ? "vector" : "first_name" ;
1235+ assertThat (
1236+ error ("from test | STATS c = COUNT(emp_no) BY " + fieldName + " | where " + functionInvocation ),
1237+ containsString ("[" + functionName + "] " + functionType + " cannot be used after STATS" )
12371238 );
1238- assertEquals ("1:24: [:] operator cannot be used after LIMIT" , error ("from test | limit 10 | where first_name:\" Anna\" " ));
1239- assertEquals ("1:24: [:] operator cannot be used after LIMIT" , error ("from test | limit 10 | where first_name : \" Anna\" " ));
1240- }
1241-
1242- public void testFieldBasedFullTextFunctions () {
1243- testFieldBasedWithNonIndexedColumn ("MATCH" , " match(text, \" cat\" )" , "function" );
1244- testFieldBasedWithNonIndexedColumn (":" , " text : \" cat\" " , "operator" );
1245- testFieldBasedWithNonIndexedColumn ("MultiMatch" , " multi_match(\" cat\" , text)" , "function" );
12461239 }
12471240
12481241 // These should pass eventually once we lift some restrictions on match function
12491242 public void testFieldBasedWithNonIndexedColumn (String functionName , String functionInvocation , String functionType ) {
12501243 assertThat (
1251- error ("from test | eval text = substring(first_name, 1) | where" + functionInvocation ),
1244+ error ("from test | eval text = substring(first_name, 1) | where " + functionInvocation ),
12521245 containsString ("[" + functionName + "] " + functionType + " cannot operate on [text], which is not a field from an index mapping" )
12531246 );
12541247 assertThat (
1255- error ("from test | eval text=concat(first_name, last_name) | where" + functionInvocation ),
1248+ error ("from test | eval text=concat(first_name, last_name) | where " + functionInvocation ),
12561249 containsString ("[" + functionName + "] " + functionType + " cannot operate on [text], which is not a field from an index mapping" )
12571250 );
12581251 var keywordInvocation = functionInvocation .replace ("text" , "text::keyword" );
0 commit comments