0

I'm trying to apply AfterMatchSkipStrategy skipPastLastEvent() into my pattern. But the problem is that i'm getting the same results as of the case when I don't apply the skipstrategy (NoSkip).

Discards every partial match that started after the match started but before it ended is the description for the skip strategy SKIP_PAST_LAST_EVENT. And as far as i understood all the partial matches would be discarded as soon as a pattern is matched.

AfterMatchSkipStrategy skipStrategy = AfterMatchSkipStrategy.skipPastLastEvent();
Pattern<GraphMap, ? > pattern2 = Pattern.<GraphMap>begin("start", skipStrategy).where(new IterativeCondition<GraphMap>() {
        @Override
        public boolean filter(GraphMap graphMap, Context<GraphMap> context) throws Exception {
            if (graphMap.getSubjectValue().equals("basketballplayer1"))
                return graphMap.getObjectValueString().equals("Miss");
            return false;
        }
    }).followedBy("middle").where(new IterativeCondition<GraphMap>() {
        @Override
        public boolean filter(GraphMap graphMap, Context<GraphMap> context) throws Exception {
            for( GraphMap previousGraphMap : context.getEventsForPattern("start")){
                if (graphMap.getSubjectValue().equals(previousGraphMap.getSubjectValue())){
                    return graphMap.getObjectValueString().equals("Basket");
                }
            }
            return false;
        }
    }).oneOrMore().followedBy("end").where(new IterativeCondition<GraphMap>() {
        @Override
        public boolean filter(GraphMap graphMap, Context<GraphMap> context) throws Exception {
            for ( GraphMap previousGraphMap : context.getEventsForPattern("middle")){
                if( graphMap.getSubjectValue().equals(previousGraphMap.getSubjectValue())){
                    return graphMap.getObjectValueString().equals("Miss");
                }
            }
            return false;
        }
    }).within(Time.seconds(10))

The Above is my Pattern sequence. In this case the output i require are sequence of (Miss Basket+ Miss) by a basketball player1. But when i have input like

Miss, Miss, Basket, Basket, Miss

I'm getting all the Matches like:

[Miss, Basket, Basket, Miss] , 
[Miss, Basket, Miss]
[Miss, Basket, Miss] {of the second miss in the sequence} etc. 

Is there something i'm doing Wrong? The output i wanted was only [Miss, Basket, Basket, Miss] and not all the other patterns as in NoSkip would give me.

Thanks in advance for any replies. It would be a huge help.

Dawid Wysakowicz
  • 3,402
  • 17
  • 33
skrshn
  • 35
  • 1
  • 1
  • 5
  • Could you provide a test case with which I could reproduce this issue? I've tried your pattern, but in my case it produces results as you expected. Few things you could improve though is rather than checking for the `subjectValue` just key your stream on it. Then in your conditions you would just check the `"Miss"/"Basket"`. – Dawid Wysakowicz Sep 20 '18 at 14:18
  • Another thing you should pay attention to is the within clause. I don't know if you are using Event or ProcessingTime, but maybe some matches just time out? – Dawid Wysakowicz Sep 20 '18 at 14:19
  • Thanks David, yes i am using Event Time so even if it times out its fine. I need the matches only within the time window. A test case would be with Data Streaming with subject - player1, player2, .. , player10 and object being "Miss" and "Basket". So i am trying to find the count of number of baskets that happen in between two misses for each player. So when i am running the code, eventhough the correct count would be there but along with that it would have all the other possibilties as well. (I am getting the size of the "middle" when creating the DataStream from PatternStream) – skrshn Sep 20 '18 at 17:23
  • What version of Flink are you using? – David Anderson Sep 20 '18 at 21:11
  • I'm using 1.4.2 – skrshn Sep 21 '18 at 06:19
  • Oh, ok. Could you update to 1.6.0? After match skip was reworked since then. – Dawid Wysakowicz Sep 21 '18 at 07:47
  • Oh okay Thanks . Has the behaviour of match skip changed after the rework ? Or is it the same as mentioned in the documents ? – skrshn Sep 21 '18 at 08:29
  • It should be the same as explained. – Dawid Wysakowicz Sep 21 '18 at 09:45
  • Thanks a lot Dawid and David for the help. – skrshn Sep 21 '18 at 11:08

0 Answers0