我正在尝试创建一个匹配“至少”出现的CEP模式。修改示例代码:
middle.oneOrMore().where(new IterativeCondition<SubEvent>() {
@Override
public boolean filter(SubEvent value, Context<SubEvent> ctx) throws Exception {
if (!value.getName().startsWith("foo")) {
return false;
}
double sum = value.getPrice();
for (Event event : ctx.getEventsForPattern("middle")) {
sum += event.getPrice();
}
return Double.compare(sum, 5.0) < 0;
}
});转到
middle.oneOrMore().where(new IterativeCondition<SubEvent>() {
@Override
public boolean filter(SubEvent value, Context<SubEvent> ctx) throws Exception {
if (!value.getName().startsWith("foo")) {
return false;
}
long count = 0;
for (Event event : ctx.getEventsForPattern("start")) {
count = count + 1;
}
return count >= MIN_COUNT;
}
});没有解决我的问题,因为条件将继续失败,并且永远不能对计数做出贡献。
我在https://ci.apache.org/projects/flink/flink-docs-release-1.3/dev/libs/cep.html中发现有
// expecting 4 occurrences
start.times(4);
// expecting 0 or 4 occurrences
start.times(4).optional();
// expecting 1 or more occurrences
start.oneOrMore();
// expecting 0 or more occurrences
start.oneOrMore().optional();是否存在像start.atLeast(5)这样的东西?
发布于 2017-07-12 15:01:56
请查看此链接以获取解决方案。它检查该模式是否会出现5次。可分次修改(Number_of_times)
[https://stackoverflow.com/questions/45033109/flink-complex-event-processing/45048866]发布于 2017-09-25 23:38:19
您可以使用.times(5)后跟相同的模式,但要与量词.oneOrMore().optional()一起使用。times恰好需要5,而zeroOrMore会给出"atLeast...“。
https://stackoverflow.com/questions/44813368
复制相似问题