Search code examples
apache-flinkflink-streamingflink-cep

How do I find the event time difference between two non consecutive events in Flink?


I want to calculate the time difference between two non consecutive event in Apache Flink. An Event consists of a name and a timestamp. Ex:

E1("A", timestamp) -> E2("B", timestamp) -> E3("C", timestamp)

In this case I want to calculate the timestamp difference between E3 and E1. Any ideas on how to make it work in Flink?


Solution

  • Since E1 & E3 have different keys, you'd need to use a non-keyed window (.windowAll()), see this doc. Since you typically can't rely on the original order of events being preserved, in your custom ProcessWindowFunction you'd have to sort them by timestamp to be able to reliably calculate a delta.