1

I want to skip matched event after first Pattern Match.

How can I use Flink's skip strategy?

I have a simple scenario if downloads > 1000 then give an alert to the user.

In my implementation, After the first match, it continuously gives alert due to increase in a number of downloads after 1000.

How can I skip all alerts after the first match?

I have read the skip strategy docs but an example or implementation will be helpful for me.

NIrav Modi
  • 6,038
  • 8
  • 32
  • 47

2 Answers2

0

CEP is more for patterns that are repeated, and it doesn't really work here. The skip strategies you are talking about are actually called "after match skip strategies" implying that you want to match the pattern more than one.

I think a better way to do this would be with a process function, something like:

class AlertUserOnce extends ProcessFunction[element, element] {

  lazy val turnOff: ValueState[Boolean] = getRuntimeContext
     .getState(new ValueStateDescriptor[Boolean]("turn-function-off", classOf[Boolean]))


  override def processElement(value: element, ctx: Context, out: Collector[element]): Unit = {
   if (turnOff.value == null && element.downloads > 1000) {
     alertUser(value)
     turnOff.update(true)
    }
    out.collect(value)
  }
}

...

stream.keyBy(...).process(new AlertUserOnce) 
0

Take a look at this example: https://github.com/eleniKougiou/Flink-cep-examples/blob/main/src/main/java/flinkCEP/cases/CEPCase4.java

 AfterMatchSkipStrategy skipToLast = AfterMatchSkipStrategy.skipToLast("start"); // Skip "start" event (a)
        // Choose after match skip strategy
        AfterMatchSkipStrategy skipStrategy = skipToLast;
        Pattern<Event, ?> pattern = Pattern.<Event>begin("start", skipStrategy).where(new SimpleCondition<>() {
            @Override
            public boolean filter(Event value){
                return value.getName().startsWith("a");
            }