Search code examples
flink-cep

how to detect trend e using flink CEP


I am new to Flink CEP. For one of our use cases, we need to implement stream analytics for temperature sensor output. if the temperature keeps on increasing for 30 minutes, need to generate an alert to the operator. I went through the Pattern API but not able to find a way to model this in Pattern? Please suggest a possible way to detect this pattern using Pattern


Solution

  • You have two possible options here that You may consider.

    First one is to use the iterative condition in cep that will check if the temperature of the current event is higher than all of previously accepted events. There is an example of the IterativeCondition in the documentation here. The key is to call the ctx.getEventsForPattern and then compare the current event with previously accepted ones.

    The second solution depends on the exact use-case, but perhaps It would be possible for You to use the sliding windows to gather elements in 30 min windows with some slide depending on the frequency of data collection. Then it should be very easy to sort the elements according to timestamps and verify that You have the growing trend in the window.