I'd like to create a view that contains a MATCH_RECOGNIZE
statement. This runs into the following error:
org.apache.flink.table.api.SqlParserException: SQL parse failed. Encountered "MATCH_RECOGNIZE" at line 3, column 79.
Was expecting one of:
<EOF>
"EXCEPT" ...
"FETCH" ...
"GROUP" ...
"HAVING" ...
"INTERSECT" ...
"LIMIT" ...
"OFFSET" ...
"ORDER" ...
"MINUS" ...
"TABLESAMPLE" ...
"UNION" ...
"WHERE" ...
"WINDOW" ...
"(" ...
"NATURAL" ...
"JOIN" ...
"INNER" ...
"LEFT" ...
"RIGHT" ...
"FULL" ...
"CROSS" ...
"," ...
"OUTER" ...
If you'd like to reproduce this issue, you could e.g. follow the Ververica training which covers MATCH_RECOGNIZE as well.
After the initial setup, create the following view:
CREATE VIEW `RideView`
AS
SELECT rideId, TIMESTAMPDIFF(MINUTE, startT, endT) AS durationMin
FROM Rides
MATCH_RECOGNIZE (
PARTITION BY rideId
ORDER BY rideTime
MEASURES
S.rideTime AS startT,
E.rideTime AS endT
AFTER MATCH SKIP PAST LAST ROW
PATTERN (S E)
DEFINE
S AS S.isStart,
E AS NOT E.isStart
);
Just running SELECT * FROM RideView
will trigger the issue.
This isn't unexpected because the Flink documentation says that
Currently, the MATCH_RECOGNIZE clause can only be applied to an append table. Furthermore, it always produces an append table as well. (https://ci.apache.org/projects/flink/flink-docs-stable/dev/table/streaming/match_recognize.html#sql-semantics).
Is there any way to overcome this limitation and use MATCH_RECOGNIZE in conjunction with CREATE VIEW AS <query>
?