use of org.apache.flink.cep.pattern.conditions.SimpleCondition in project flink-mirror by flink-ci.
the class GroupITCase method testGroupNotFollowedBy.
@Test
public void testGroupNotFollowedBy() throws Exception {
List<StreamRecord<Event>> inputEvents = new ArrayList<>();
Event c = new Event(40, "c", 1.0);
Event a1 = new Event(41, "a", 2.0);
Event b1 = new Event(42, "b", 3.0);
Event d = new Event(43, "d", 3.0);
Event a2 = new Event(44, "a", 4.0);
Event b2 = new Event(45, "b", 5.0);
Event e = new Event(46, "e", 6.0);
inputEvents.add(new StreamRecord<>(c, 1));
inputEvents.add(new StreamRecord<>(a1, 2));
inputEvents.add(new StreamRecord<>(b1, 3));
inputEvents.add(new StreamRecord<>(d, 4));
inputEvents.add(new StreamRecord<>(a2, 5));
inputEvents.add(new StreamRecord<>(b2, 6));
inputEvents.add(new StreamRecord<>(e, 7));
// c (a b) ^d e
Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("c");
}
}).followedByAny(Pattern.<Event>begin("middle1").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("a");
}
}).followedBy("middle2").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("b");
}
})).notFollowedBy("notPattern").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("d");
}
}).followedBy("end").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("e");
}
});
NFA<Event> nfa = compile(pattern, false);
final List<List<Event>> resultingPatterns = feedNFA(inputEvents, nfa);
comparePatterns(resultingPatterns, Lists.<List<Event>>newArrayList(Lists.newArrayList(c, a2, b2, e)));
}
use of org.apache.flink.cep.pattern.conditions.SimpleCondition in project flink-mirror by flink-ci.
the class GroupITCase method testGroupNotNext.
@Test
public void testGroupNotNext() throws Exception {
List<StreamRecord<Event>> inputEvents = new ArrayList<>();
Event c = new Event(40, "c", 1.0);
Event a1 = new Event(41, "a", 2.0);
Event b1 = new Event(42, "b", 3.0);
Event d = new Event(43, "d", 3.0);
Event a2 = new Event(44, "a", 4.0);
Event b2 = new Event(45, "b", 5.0);
Event e = new Event(46, "e", 6.0);
inputEvents.add(new StreamRecord<>(c, 1));
inputEvents.add(new StreamRecord<>(a1, 2));
inputEvents.add(new StreamRecord<>(b1, 3));
inputEvents.add(new StreamRecord<>(d, 4));
inputEvents.add(new StreamRecord<>(a2, 5));
inputEvents.add(new StreamRecord<>(b2, 6));
inputEvents.add(new StreamRecord<>(e, 7));
// c (a b) next ^d e
Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("c");
}
}).followedByAny(Pattern.<Event>begin("middle1").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("a");
}
}).followedBy("middle2").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("b");
}
})).notNext("notPattern").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("d");
}
}).followedBy("end").where(new SimpleCondition<Event>() {
private static final long serialVersionUID = 5726188262756267490L;
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("e");
}
});
NFA<Event> nfa = compile(pattern, false);
final List<List<Event>> resultingPatterns = feedNFA(inputEvents, nfa);
comparePatterns(resultingPatterns, Lists.<List<Event>>newArrayList(Lists.newArrayList(c, a2, b2, e)));
}
use of org.apache.flink.cep.pattern.conditions.SimpleCondition in project flink-mirror by flink-ci.
the class AfterMatchSkipITCase method testSkipPastLast.
@Test
public void testSkipPastLast() throws Exception {
List<StreamRecord<Event>> streamEvents = new ArrayList<>();
Event a1 = new Event(1, "a", 0.0);
Event a2 = new Event(2, "a", 0.0);
Event a3 = new Event(3, "a", 0.0);
Event a4 = new Event(4, "a", 0.0);
Event a5 = new Event(5, "a", 0.0);
Event a6 = new Event(6, "a", 0.0);
streamEvents.add(new StreamRecord<Event>(a1));
streamEvents.add(new StreamRecord<Event>(a2));
streamEvents.add(new StreamRecord<Event>(a3));
streamEvents.add(new StreamRecord<Event>(a4));
streamEvents.add(new StreamRecord<Event>(a5));
streamEvents.add(new StreamRecord<Event>(a6));
Pattern<Event, ?> pattern = Pattern.<Event>begin("start", AfterMatchSkipStrategy.skipPastLastEvent()).where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event value) throws Exception {
return value.getName().equals("a");
}
}).times(3);
NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).build();
List<List<Event>> resultingPatterns = nfaTestHarness.feedRecords(streamEvents);
comparePatterns(resultingPatterns, Lists.newArrayList(Lists.newArrayList(a1, a2, a3), Lists.newArrayList(a4, a5, a6)));
}
use of org.apache.flink.cep.pattern.conditions.SimpleCondition in project flink-mirror by flink-ci.
the class AfterMatchSkipITCase method testSkipToFirstWithOneOrMoreAtBeginning.
/**
* Example from docs.
*/
@Test
public void testSkipToFirstWithOneOrMoreAtBeginning() throws Exception {
List<StreamRecord<Event>> streamEvents = new ArrayList<>();
Event a1 = new Event(1, "a1", 0.0);
Event a2 = new Event(2, "a2", 0.0);
Event a3 = new Event(3, "a3", 0.0);
Event b1 = new Event(4, "b1", 0.0);
streamEvents.add(new StreamRecord<>(a1));
streamEvents.add(new StreamRecord<>(a2));
streamEvents.add(new StreamRecord<>(a3));
streamEvents.add(new StreamRecord<>(b1));
Pattern<Event, ?> pattern = Pattern.<Event>begin("a", AfterMatchSkipStrategy.skipToFirst("a")).where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event value) throws Exception {
return value.getName().contains("a");
}
}).oneOrMore().consecutive().greedy().next("b").where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event value) throws Exception {
return value.getName().contains("b");
}
});
NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).build();
List<List<Event>> resultingPatterns = nfaTestHarness.feedRecords(streamEvents);
comparePatterns(resultingPatterns, Lists.newArrayList(Lists.newArrayList(a1, a2, a3, b1), Lists.newArrayList(a2, a3, b1), Lists.newArrayList(a3, b1)));
}
use of org.apache.flink.cep.pattern.conditions.SimpleCondition in project flink-mirror by flink-ci.
the class AfterMatchSkipITCase method testSkipToFirst.
@Test
public void testSkipToFirst() throws Exception {
List<StreamRecord<Event>> streamEvents = new ArrayList<>();
Event ab1 = new Event(1, "ab", 0.0);
Event ab2 = new Event(2, "ab", 0.0);
Event ab3 = new Event(3, "ab", 0.0);
Event ab4 = new Event(4, "ab", 0.0);
Event ab5 = new Event(5, "ab", 0.0);
Event ab6 = new Event(6, "ab", 0.0);
streamEvents.add(new StreamRecord<Event>(ab1));
streamEvents.add(new StreamRecord<Event>(ab2));
streamEvents.add(new StreamRecord<Event>(ab3));
streamEvents.add(new StreamRecord<Event>(ab4));
streamEvents.add(new StreamRecord<Event>(ab5));
streamEvents.add(new StreamRecord<Event>(ab6));
Pattern<Event, ?> pattern = Pattern.<Event>begin("start", AfterMatchSkipStrategy.skipToFirst("end")).where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event value) throws Exception {
return value.getName().contains("a");
}
}).times(2).next("end").where(new SimpleCondition<Event>() {
@Override
public boolean filter(Event value) throws Exception {
return value.getName().contains("b");
}
}).times(2);
NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).build();
List<List<Event>> resultingPatterns = nfaTestHarness.feedRecords(streamEvents);
comparePatterns(resultingPatterns, Lists.newArrayList(Lists.newArrayList(ab1, ab2, ab3, ab4), Lists.newArrayList(ab3, ab4, ab5, ab6)));
}
Aggregations