【问题标题】:Apach Flink CEP "At Least" ConditionApache Flink CEP“至少”条件
【发布时间】: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


【解决方案1】:

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

[https://stackoverflow.com/questions/45033109/flink-complex-event-processing/45048866]

【讨论】:

    【解决方案2】:

    您可以使用.times(5),后跟相同的模式,但使用量词.oneOrMore().optional()times 正好需要 5,zeroOrMore 会给你“atLeast...”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-18
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      相关资源
      最近更新 更多