MartijnVisser commented on code in PR #30256:
URL: https://github.com/apache/flink/pull/30256#discussion_r4790554393
##########
docs/content/docs/sql/reference/queries/match_recognize.md:
##########
@@ -1117,6 +1117,9 @@ Unsupported features include:
* Exclusion - `PATTERN ({- A -} B)` meaning that `A` will be looked for but
will not participate
in the output. This works only for the `ALL ROWS PER MATCH` mode.
* Reluctant optional quantifier - `PATTERN A??` only the greedy optional
quantifier is supported.
+ * Optional variable after a greedy variable - a variable with the `?`, `??`,
`*` or `*?`
+ quantifier can not directly follow a variable with a greedy quantifier
(e.g. `+`, `*`, `{2,}`).
+ Thus, `PATTERN (A+ B? C)` is not a valid pattern, while `PATTERN (A+
B{0,1} C)` is.
Review Comment:
`A+ B{0,1} C` fails with the same error, since `{0,1}` reaches the planner
as `?`. I think the second half should go.
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/physical/common/CommonPhysicalMatchRule.java:
##########
@@ -136,6 +142,44 @@ private void validateAmbiguousColumns(FlinkLogicalMatch
logicalMatch) {
}
}
+ // CEP rejects an optional pattern after a greedy one
+ private static void validateOptionalAfterGreedy(RexNode pattern) {
+ final List<RexNode> variables = new ArrayList<>();
+ flattenConcat(pattern, variables);
+ // the name of the previous variable if it is greedy, otherwise null
+ String previousGreedy = null;
+ for (RexNode variable : variables) {
+ if (!(variable instanceof RexCall)
+ || ((RexCall) variable).getOperator()
+ != SqlStdOperatorTable.PATTERN_QUANTIFIER) {
+ previousGreedy = null;
+ continue;
+ }
+ final List<RexNode> operands = ((RexCall) variable).getOperands();
+ final String name =
+ operands.get(0) instanceof RexLiteral
+ ? ((RexLiteral)
operands.get(0)).getValueAs(String.class)
+ : operands.get(0).toString();
+ final long start = ((RexLiteral)
operands.get(1)).getValueAs(Long.class);
+ final long end = ((RexLiteral)
operands.get(2)).getValueAs(Long.class);
+ final boolean greedy = !((RexLiteral)
operands.get(3)).getValueAs(Boolean.class);
+ if (previousGreedy != null &&
MatchUtil.isOptionalQuantifier(start, end)) {
+ throw new ValidationException(
+ MatchUtil.optionalAfterGreedyMessage(name,
previousGreedy));
+ }
+ previousGreedy = MatchUtil.isGreedyQuantifier(start, end, greedy)
? name : null;
Review Comment:
With `previousGreedy = name` all tests still pass and `A+? B? C` is
rejected. Could a test cover a non-greedy variable before the optional one?
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/physical/common/CommonPhysicalMatchRule.java:
##########
@@ -136,6 +142,44 @@ private void validateAmbiguousColumns(FlinkLogicalMatch
logicalMatch) {
}
}
+ // CEP rejects an optional pattern after a greedy one
+ private static void validateOptionalAfterGreedy(RexNode pattern) {
+ final List<RexNode> variables = new ArrayList<>();
+ flattenConcat(pattern, variables);
+ // the name of the previous variable if it is greedy, otherwise null
+ String previousGreedy = null;
+ for (RexNode variable : variables) {
+ if (!(variable instanceof RexCall)
+ || ((RexCall) variable).getOperator()
+ != SqlStdOperatorTable.PATTERN_QUANTIFIER) {
+ previousGreedy = null;
+ continue;
+ }
+ final List<RexNode> operands = ((RexCall) variable).getOperands();
+ final String name =
+ operands.get(0) instanceof RexLiteral
+ ? ((RexLiteral)
operands.get(0)).getValueAs(String.class)
+ : operands.get(0).toString();
Review Comment:
For `A+ (B C)?` this reports `'(_UTF-16LE'B', _UTF-16LE'C')'` as the
variable instead of the group pattern error from master. Skipping non-literal
operands avoids that.
--
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]