0
votes

I am new to Flink CEP and have been playing around with the patterns for better understanding of them. I have a simple case of a "begin" & a followedBy". I notice that in the case of followedBy, the same event is looping through it multiple times. What am I missing here?

Pattern match_win = Pattern.begin("first").where(new SimpleCondition() {

    public boolean filter(HitDTO hitDTO) throws Exception {
        boolean result = false;
        if (hitDTO.getHitScore() == 4)
        {
            System.out.println("First:" + hitDTO + ": " + hitDTO.getHitScore());
            result = true;
        }
        return result;
    }
}).followedBy("next").where(new SimpleCondition<HitDTO>(){

    public boolean filter(HitDTO hitDTO) throws Exception
    {
        boolean result = false;

        if (hitDTO.getHitScore() == 6)
        {
            System.out.println("Next:" + hitDTO+ ": " + hitDTO.getHitScore());
            result = true;
        }
        return result;
    }
});

I am passing in 4,4,6

Parallelism is set at 1.

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment().setParallelism(1);

However, this is what I see in the logs for the printout within the patterns, where 6 is looping 4 times when it was passed in only once.

First:com.rs.dto.HitDTO@17619295: 4

First:com.rs.dto.HitDTO@c108f70: 4

Next:com.rs.dto.HitDTO@5d13aab8: 6

Next:com.rs.dto.HitDTO@5d13aab8: 6

Next:com.rs.dto.HitDTO@5d13aab8: 6

Next:com.rs.dto.HitDTO@5d13aab8: 6

Just wondering why the same event is looping through multiple times but the outcome is correct.

Thanks for your answer.

1

1 Answers

0
votes

It is normal that the process of attempting to match a pattern to an input sequence will involve multiple evaluations of various components of the pattern. That's how pattern matching works: the pattern is compiled to a finite state machine, and all possible paths the input might take through that FSM are considered, looking for paths that lead to the terminal, matching state. If you're not careful in how you define your pattern, this can lead to a combinatorial explosion of effort.