Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flink Apach Flink CEP“;至少;条件_Apache Flink - Fatal编程技术网

Apache flink Apach Flink CEP“;至少;条件

Apache flink Apach Flink CEP“;至少;条件,apache-flink,Apache Flink,我正在尝试创建一个CEP模式,该模式与“至少”事件匹配。修改示例代码: middle.oneOrMore().where(new IterativeCondition<SubEvent>() { @Override public boolean filter(SubEvent value, Context<SubEvent> ctx) throws Exception { if (!value.getName().startsWith("f

我正在尝试创建一个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;
    }
});

是否存在至少(5)个类似start.的选项?

检查此链接以获取解决方案。它检查模式是否出现5次。您可以按次修改它(次数)

您可以使用
.times(5)
,后跟相同的模式,但使用量词
.oneOrMore().optional()
times
需要精确的5次,而
zero或more
将为您提供“至少…”。

可以使用next()将times(4)与one或more()组合起来?我还没有试过,但似乎应该能用。谢谢,我玩了《泰晤士报》(n)。下一个(“模式2”)。一个或多个(),但它似乎没有达到我需要的效果。我还玩了oneOrMore().next(“pattern2”).time(n),它产生了更接近的结果。我将继续调查这个问题,并在稍后分享我的发现。
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;
    }
});
// 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();
[https://stackoverflow.com/questions/45033109/flink-complex-event-processing/45048866]