Flink CEP:量词Quantifiers详解
问题导读
1.什么是量词?
2.量词的作用是什么?
3.greedy()的作用是什么?
4.如果事件可以不发生,该使用什么量词来表示?
量词【难点,需要细看】
这里需要对量词做一个解释,量即为次数,也就是说在cep中,通过量词来控制次数。那么量词都有哪些?
pattern.oneOrMore(),指事件发生一次或则多次
pattern.times(#ofTimes)ofTimes是指事件发生的次数,也就是期望发生几次,比如pattern.times(4),代表期望发生4次
pattern.times(#fromTimes, #toTimes),这里指定最少发生次数和最大发生次数。比如pattern.times(2, 4),也就是最少发生2次,最多发生4次,那么也可能发生3次
pattern.greedy() ,这样是模式进入循环模式
pattern.optional()代表这个事情可以发生,或则不发生。我们来看下面
这里重点摘出来
// expecting 4 occurrences
start.times(4)
// expecting 0 or 4 occurrences
start.times(4).optional()
//start.times(4)这里大表期望发生4次
//start.times(4).optional()加上optional()代表不发生4次,那么就是0次,也就是事件可以不发生
// expecting 0, 2, 3 or 4 occurrences
start.times(2, 4).optional()
//同理这里在解释下start.times(2, 4),可能发生2,3,4次
//start.times(2, 4).optional()加上optional(),代表可以不发生也就是0次,2,3,4次
// expecting 4 occurrences
start.times(4)
// expecting 0 or 4 occurrences
start.times(4).optional()
//start.times(4)这里大表期望发生4次
//start.times(4).optional()加上optional()代表不发生4次,那么就是0次,也就是事件可以不发生
// expecting 2, 3 or 4 occurrences
start.times(2, 4)
// expecting 2, 3 or 4 occurrences and repeating as many as possible
start.times(2, 4).greedy()
// expecting 0, 2, 3 or 4 occurrences
start.times(2, 4).optional()
//同理这里在解释下start.times(2, 4),可能发生2,3,4次
//start.times(2, 4).optional()加上optional(),代表可以不发生,2,3,4次
// expecting 0, 2, 3 or 4 occurrences and repeating as many as possible
start.times(2, 4).optional().greedy()
// expecting 1 or more occurrences
start.oneOrMore()
// expecting 1 or more occurrences and repeating as many as possible
start.oneOrMore().greedy()
// expecting 0 or more occurrences
start.oneOrMore().optional()
// expecting 0 or more occurrences and repeating as many as possible
start.oneOrMore().optional().greedy()
// expecting 2 or more occurrences
start.timesOrMore(2)
// expecting 2 or more occurrences and repeating as many as possible
start.timesOrMore(2).greedy()
// expecting 0, 2 or more occurrences
start.timesOrMore(2).optional()
// expecting 0, 2 or more occurrences and repeating as many as possible
start.timesOrMore(2).optional().greedy()
最新经典文章,欢迎关注公众号http://www.aboutyun.com/data/attachment/forum/201903/18/215536lzpn7n3u7m7u90vm.jpg
感谢分享
页:
[1]