Browse Source

Match can't be used after STATS .. BY until filters can be pushed down below STATS (#116642) (#116791)

(cherry picked from commit e2e8a46a8d3cd3a52110128d964e1a82aca0e9de)
Carlos Delgado 11 months ago
parent
commit
8b8cf5f60c

+ 1 - 1
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java

@@ -688,7 +688,7 @@ public class Verifier {
                 plan,
                 plan,
                 condition,
                 condition,
                 Match.class,
                 Match.class,
-                lp -> (lp instanceof Limit == false),
+                lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
                 m -> "[" + m.functionName() + "] " + m.functionType(),
                 m -> "[" + m.functionName() + "] " + m.functionType(),
                 failures
                 failures
             );
             );

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

@@ -1183,6 +1183,10 @@ public class VerifierTests extends ESTestCase {
             "1:24: [MATCH] function cannot be used after LIMIT",
             "1:24: [MATCH] function cannot be used after LIMIT",
             error("from test | limit 10 | where match(first_name, \"Anna\")")
             error("from test | limit 10 | where match(first_name, \"Anna\")")
         );
         );
+        assertEquals(
+            "1:47: [MATCH] function cannot be used after STATS",
+            error("from test | STATS c = AVG(salary) BY gender | where match(gender, \"F\")")
+        );
     }
     }
 
 
     public void testMatchFunctionAndOperatorHaveCorrectErrorMessages() throws Exception {
     public void testMatchFunctionAndOperatorHaveCorrectErrorMessages() throws Exception {