MartijnVisser commented on code in PR #30256:
URL: https://github.com/apache/flink/pull/30256#discussion_r4786515121


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/common/CommonExecMatch.java:
##########
@@ -433,6 +434,17 @@ private Pattern<RowData, RowData> applyQuantifier(
                 Pattern<RowData, RowData> pattern, int startNum, int endNum, 
boolean greedy) {
             boolean isOptional = startNum == 0 && endNum == 1;
 
+            // CEP's optional(), used for ? and *, rejects a greedy previous 
pattern
+            if (startNum == 0

Review Comment:
   This runs where CEP already threw, so `COMPILE PLAN` still succeeds and the 
plan only fails on execute or `loadPlan`, as on master. I think the check 
belongs in `CommonPhysicalMatchRule`, like FLINK-40449 did for sort.



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/common/CommonExecMatch.java:
##########
@@ -433,6 +434,17 @@ private Pattern<RowData, RowData> applyQuantifier(
                 Pattern<RowData, RowData> pattern, int startNum, int endNum, 
boolean greedy) {
             boolean isOptional = startNum == 0 && endNum == 1;
 
+            // CEP's optional(), used for ? and *, rejects a greedy previous 
pattern
+            if (startNum == 0
+                    && (endNum == 1 || endNum == -1)
+                    && pattern.getPrevious() != null
+                    && pattern.getPrevious()
+                            .getQuantifier()
+                            
.hasProperty(Quantifier.QuantifierProperty.GREEDY)) {
+                throw new ValidationException(
+                        "An optional pattern variable is not allowed directly 
after a greedy pattern variable.");

Review Comment:
   It would help if the message named both variables. The restriction also 
needs an entry under Known Limitations in the MATCH_RECOGNIZE docs.



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/common/CommonExecMatch.java:
##########
@@ -433,6 +434,17 @@ private Pattern<RowData, RowData> applyQuantifier(
                 Pattern<RowData, RowData> pattern, int startNum, int endNum, 
boolean greedy) {
             boolean isOptional = startNum == 0 && endNum == 1;
 
+            // CEP's optional(), used for ? and *, rejects a greedy previous 
pattern
+            if (startNum == 0
+                    && (endNum == 1 || endNum == -1)

Review Comment:
   `A+ B{0,3} C` is still accepted and runs, because `times(0, n)` marks the 
pattern optional without going through `optional()`. Is that intended, given 
the new message?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to