分享

Flink难点:彻底明白CEP3:独立模式【Patterns】操作Pattern Operation

pig2 2019-6-11 10:29:31 发表于 连载型 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 3 13709
问题导读

1.独立模式有哪些条件?
2.循环模式模式该如何停止?
3.subtype的作用是什么?


上一篇:
Flink难点:彻底明白CEP2,条件分类
http://www.aboutyun.com/forum.php?mod=viewthread&tid=27295


1.where(condition)        
定义当前模式的条件。 要匹配模式,事件必须满足条件。
[mw_shl_code=scala,true]pattern.where(event => ... /* some condition */)
[/mw_shl_code]
[mw_shl_code=Java,true]pattern.where(new IterativeCondition<Event>() {
    @Override
    public boolean filter(Event value, Context ctx) throws Exception {
        return ... // some condition
    }
});[/mw_shl_code]

2.or(condition)        

添加与现有条件进行“或”运算的新条件。 仅当事件至少通过其中一个条件时,才能匹配该模式:
[mw_shl_code=scala,true]pattern.where(event => ... /* some condition */)
    .or(event => ... /* alternative condition */)[/mw_shl_code]

[mw_shl_code=java,true]pattern.where(new IterativeCondition<Event>() {
    @Override
    public boolean filter(Event value, Context ctx) throws Exception {
        return ... // some condition
    }
}).or(new IterativeCondition<Event>() {
    @Override
    public boolean filter(Event value, Context ctx) throws Exception {
        return ... // alternative condition
    }
});[/mw_shl_code]

3.until(condition)        

指定循环模式的停止条件。 意味着如果匹配给定条件的事件发生,则不再接受该模式中的事件。

仅适用于oneOrMore()

注意:它允许在基于事件的条件下清除相应模式的状态。


[mw_shl_code=java,true]pattern.oneOrMore().until(new IterativeCondition<Event>() {
    @Override
    public boolean filter(Event value, Context ctx) throws Exception {
        return ... // alternative condition
    }
});[/mw_shl_code]

[mw_shl_code=scala,true]pattern.oneOrMore().until(event => ... /* some condition */)
[/mw_shl_code]

4.subtype(subClass)        

定义当前模式的子类型条件。 如果事件属于此子类型,则事件只能匹配该模式:
[mw_shl_code=scala,true]pattern.subtype(classOf[SubEvent])
[/mw_shl_code]
[mw_shl_code=java,true]pattern.subtype(SubEvent.class);
[/mw_shl_code]

5.oneOrMore()        

指定此模式至少需要出现一次匹配事件。

默认情况下,使用宽松的内部连续性(在后续事件之间)。 有关内部连续性的更多信息,请参阅连续

注意:建议使用until()或within()来启用状态清除

[mw_shl_code=java,true]pattern.oneOrMore();
[/mw_shl_code]
[mw_shl_code=scala,true]pattern.oneOrMore()
[/mw_shl_code]

6.timesOrMore(#times)        

指定此模式至少需要#times【次数】出现匹配事件。

默认情况下,使用宽松的内部连续性(在后续事件之间)。 有关内部连续性的更多信息,请参阅连续


[mw_shl_code=scala,true]pattern.timesOrMore(2)
[/mw_shl_code]
[mw_shl_code=java,true]pattern.timesOrMore(2);
[/mw_shl_code]

7.times(#ofTimes)

指定此模式需要匹配事件的确切出现次数。

默认情况下,使用宽松的内部连续性(在后续事件之间)。 有关内部连续性的更多信息,同6。

[mw_shl_code=scala,true]pattern.times(2);
[/mw_shl_code]
[mw_shl_code=java,true]pattern.times(2)
[/mw_shl_code]

8.times(#fromTimes, #toTimes)        

指定此模式期望在匹配事件的#fromTimes和#toTimes之间出现。
默认情况下,使用宽松的内部连续性(在后续事件之间)。 有关内部连续性的更多信息,同6。

[mw_shl_code=scala,true]pattern.times(2, 4)
[/mw_shl_code]
[mw_shl_code=java,true]pattern.times(2, 4);
[/mw_shl_code]

9.optional()        

指定此模式是可选的,即根本不会发生或则发生。 这适用于所有上述量词。
[mw_shl_code=java,true]pattern.oneOrMore().optional();
[/mw_shl_code]

[mw_shl_code=scala,true]pattern.oneOrMore().optional()
[/mw_shl_code]

10.greedy()

指定此模式是贪婪的,即它将尽可能多地重复。 这仅适用于量词,目前不支持组(group )模式。
[mw_shl_code=scala,true]pattern.oneOrMore().greedy();
[/mw_shl_code]
[mw_shl_code=Java,true]pattern.oneOrMore().greedy()
[/mw_shl_code]

最新经典文章,欢迎关注公众号

加入About云知识星球,获取更多实用资料

本帖被以下淘专辑推荐:

已有(3)人评论

跳转到指定楼层
zuliangzhu 发表于 2019-10-10 13:33:31
写的非常棒,学习了
回复

使用道具 举报

金瞳 发表于 2019-12-9 15:26:35
1.独立模式有哪些条件?
- where(condition)
- or(condition)
- until(condition)
- subtype(subClass)
- oneOrMore()
- timesOrMore(#times)
- times(#ofTimes)
- times(#fromTimes, #toTimes)       
- optional()
- greedy()


2.循环模式模式该如何停止?
- until,within()

3.subtype的作用是什么?
- 将接受事件的类型限制为初始事件类型的子类型。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条