【发布时间】:2017-06-28 22:13:03
【问题描述】:
我正在尝试创建与“至少”匹配的 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) 的东西?
【问题讨论】:
-
也许使用 next() 将 times(4) 与 oneOrMore() 结合起来?没试过,但好像应该可以。
-
谢谢,我玩过 times(n).next("pattern2").oneOrMore(),但它似乎没有达到我的要求。我还玩了 oneOrMore().next("pattern2").time(n),它产生了更接近的结果。我将继续调查此问题并稍后分享我的发现。
标签: apache-flink