Search code examples
apache-flinkflink-streamingflink-sqlflink-cep

Is it possible for Flink CEP SQL to run on a hopping window


My typical use case is to keep monitoring an event stream to detect event patterns, but I expect the window is a hopping one. By default, interval ... in CEP SQL should define a tumbling window. Is it possible to have a hopping window for CEP pattern matching? or any other solutions?

Thanks


Solution

  • It is possible to nest time-based queries in Flink SQL. So you can define a MATCH_RECOGNIZE clause on a view that did a windowing before.

    Here is some sketch example:

    -- get the rowtime from the window operation
    CREATE TEMPORARY VIEW my_view AS
      SELECT HOP_ROWTIME(rowtime, INTERVAL '1' SECOND, INTERVAL '2' SECOND) AS windowedRowtime, ...
      FROM my_table
      GROUP BY HOP(rowtime, INTERVAL '1' SECOND, INTERVAL '2' SECOND);
    
    -- use the new rowtime for MATCH_RECOGNIZE
    SELECT * FROM my_view MATCH_RECOGNIZE(ORDER BY windowedRowtime ...)