Martijn Visser created FLINK-41692:
--------------------------------------

             Summary: MATCH_RECOGNIZE greedy quantifiers do not backtrack and 
silently drop matches
                 Key: FLINK-41692
                 URL: https://issues.apache.org/jira/browse/FLINK-41692
             Project: Flink
          Issue Type: Bug
          Components: Library / CEP
            Reporter: Martijn Visser


A greedy quantifier in MATCH_RECOGNIZE never gives rows back to the next 
pattern variable, so the match is lost when both conditions accept the same 
row. Streaming and batch mode behave the same.

{code:sql}
SELECT * FROM t MATCH_RECOGNIZE (PARTITION BY k ORDER BY ts
  MEASURES FIRST(id) AS f, LAST(id) AS l
  AFTER MATCH SKIP PAST LAST ROW
  PATTERN (A B+ C)
  DEFINE A AS A.kind = 'a', B AS B.price < 5, C AS C.price < 3)
{code}

With prices 1, 4, 2, 9 and the first row of kind 'a', Flink returns no row, 
while Trino returns A=1, B=4, C=2. With {{B+?}} Flink finds that match too. 
{{NFACompiler#updateWithGreedyCondition}} only lets the next variable take rows 
the greedy one rejects. This was also asked on the user mailing list in 2019: 
https://lists.apache.org/thread/sr5k0hrvssgmdrkt3kqrgjx1bm309sn3



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to