[ https://issues.apache.org/jira/browse/FLINK-6197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15944781#comment-15944781 ]
ASF GitHub Bot commented on FLINK-6197: --------------------------------------- Github user dawidwys commented on a diff in the pull request: https://github.com/apache/flink/pull/3624#discussion_r108364477 --- Diff: docs/dev/libs/cep.md --- @@ -124,13 +124,70 @@ val start : Pattern[Event, _] = Pattern.begin("start") </div> </div> -Each state must have an unique name to identify the matched events later on. +Each state must have a unique name to identify the matched events later on. Additionally, we can specify a filter condition for the event to be accepted as the start event via the `where` method. +These filtering conditions can be either an `IterativeCondition` or a `SimpleCondition`. + +**Iterative Conditions:** This type of conditions can iterate over the previously accepted elements in the pattern and +decide to accept a new element or not, based on some statistic over those elements. + +Below is the code for an iterative condition that accepts elements whose name start with "foo" and for which, the sum +of the prices of the previously accepted elements for a state named "middle", plus the price of the current event, do +not exceed the value of 5.0. Iterative condition can be very powerful, especially in combination with quantifiers, e.g. +`oneToMany` or `zeroToMany`. + +<div class="codetabs" markdown="1"> +<div data-lang="java" markdown="1"> +{% highlight java %} +start.where(new IterativeCondition<SubEvent>() { + @Override + public boolean filter(SubEvent value, Context<SubEvent> ctx) throws Exception { + if (!value.getName().startsWith("foo")) { + return false; + } + + double sum = 0.0; + for (Event event : ctx.getEventsForPattern("middle")) { + sum += event.getPrice(); + } + sum += value.getPrice(); + return Double.compare(sum, 5.0) < 0; + } +}); +{% endhighlight %} +</div> + +<div data-lang="scala" markdown="1"> +{% highlight scala %} +start.where( --- End diff -- It is not that obvious but the `lazy` keyword plays the role of avoiding calling `getEventsForPattern`. But I agree the java-ish way is more straightforward. > Add support for iterative conditions. > ------------------------------------- > > Key: FLINK-6197 > URL: https://issues.apache.org/jira/browse/FLINK-6197 > Project: Flink > Issue Type: Bug > Components: CEP > Affects Versions: 1.3.0 > Reporter: Kostas Kloudas > Assignee: Kostas Kloudas > Fix For: 1.3.0 > > > So far, the {{where}} clause only supported simple {{FilterFunction}} > conditions. > With this, we want to add support for conditions where the an event is > accepted not only based on its own properties, e.g. name, as it was before, > but also based on some statistic computed over previously accepted events in > the pattern, e.g. if the price is higher than the average of the prices of > the previously accepted events. > This in combination with the recently added quantifiers will allow for a lot > more expressive patterns. -- This message was sent by Atlassian JIRA (v6.3.15#6346)