You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2016/08/19 13:50:00 UTC
[2/2] flink git commit: [FLINK-3319] [cep] Add documentation for or
function
[FLINK-3319] [cep] Add documentation for or function
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f0fef6f4
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f0fef6f4
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f0fef6f4
Branch: refs/heads/master
Commit: f0fef6f44a53baf24ab38f1392eb321462d3f4fa
Parents: 266c76b
Author: Till Rohrmann <tr...@apache.org>
Authored: Fri Aug 19 15:47:34 2016 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Fri Aug 19 15:47:34 2016 +0200
----------------------------------------------------------------------
docs/apis/streaming/libs/cep.md | 56 ++++++++++++++++++++
.../flink/cep/scala/pattern/Pattern.scala | 11 ++++
.../org/apache/flink/cep/pattern/Pattern.java | 12 ++---
3 files changed, 73 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/f0fef6f4/docs/apis/streaming/libs/cep.md
----------------------------------------------------------------------
diff --git a/docs/apis/streaming/libs/cep.md b/docs/apis/streaming/libs/cep.md
index b313451..ef35d32 100644
--- a/docs/apis/streaming/libs/cep.md
+++ b/docs/apis/streaming/libs/cep.md
@@ -178,6 +178,33 @@ As it can be seen here, the subtype condition can also be combined with an addit
In fact you can always provide multiple conditions by calling `where` and `subtype` multiple times.
These conditions will then be combined using the logical AND operator.
+In order to construct or conditions, one has to call the `or` method with a respective filter function.
+Any existing filter function is then ORed with the given one.
+
+<div class="codetabs" markdown="1">
+<div data-lang="java" markdown="1">
+{% highlight java %}
+pattern.where(new FilterFunction<Event>() {
+ @Override
+ public boolean filter(Event value) {
+ return ... // some condition
+ }
+}).or(new FilterFunction<Event>() {
+ @Override
+ public boolean filter(Event value) {
+ return ... // or condition
+ }
+});
+{% endhighlight %}
+</div>
+
+<div data-lang="scala" markdown="1">
+{% highlight scala %}
+pattern.where(event => ... /* some condition */).or(event => ... /* or condition */)
+{% endhighlight %}
+</div>
+</div>
+
Next, we can append further states to detect complex patterns.
We can control the contiguity of two succeeding events to be accepted by the pattern.
@@ -285,6 +312,25 @@ patternState.where(new FilterFunction<Event>() {
{% endhighlight %}
</td>
</tr>
+ <tr>
+ <td><strong>Or</strong></td>
+ <td>
+ <p>Adds a new filter condition which is ORed with an existing filter condition. Only if an event passes the filter condition, it can match the state:</p>
+{% highlight java %}
+patternState.where(new FilterFunction<Event>() {
+ @Override
+ public boolean filter(Event value) throws Exception {
+ return ... // some condition
+ }
+}).or(new FilterFunction<Event>() {
+ @Override
+ public boolean filter(Event value) throws Exception {
+ return ... // alternative condition
+ }
+});
+{% endhighlight %}
+ </td>
+ </tr>
<tr>
<td><strong>Subtype</strong></td>
<td>
@@ -352,6 +398,16 @@ patternState.where(event => ... /* some condition */)
{% endhighlight %}
</td>
</tr>
+ <tr>
+ <td><strong>Or</strong></td>
+ <td>
+ <p>Adds a new filter condition which is ORed with an existing filter condition. Only if an event passes the filter condition, it can match the state:</p>
+{% highlight scala %}
+patternState.where(event => ... /* some condition */)
+ .or(event => ... /* alternative condition */)
+{% endhighlight %}
+ </td>
+ </tr>
<tr>
<td><strong>Subtype</strong></td>
<td>
http://git-wip-us.apache.org/repos/asf/flink/blob/f0fef6f4/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala b/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
index 592599c..cc3b03c 100644
--- a/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
+++ b/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
@@ -127,6 +127,17 @@ class Pattern[T , F <: T](jPattern: JPattern[T, F]) {
}
/**
+ * Specifies a filter condition which is ORed with an existing filter function.
+ *
+ * @param filter Or filter function
+ * @return The same pattern operator where the new filter condition is set
+ */
+ def or(filter: FilterFunction[F]): Pattern[T, F] = {
+ jPattern.or(filter)
+ this
+ }
+
+ /**
* Specifies a filter condition which has to be fulfilled by an event in order to be matched.
*
* @param filterFun Filter condition
http://git-wip-us.apache.org/repos/asf/flink/blob/f0fef6f4/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
index 14aed5d..9269dcb 100644
--- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
+++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
@@ -93,18 +93,18 @@ public class Pattern<T, F extends T> {
}
/**
- * Specifies a filter condition if fulfilled by an event will match.
+ * Specifies a filter condition which is ORed with an existing filter function.
*
- * @param newFilterFunction Filter condition
+ * @param orFilterFunction OR filter condition
* @return The same pattern operator where the new filter condition is set
*/
- public Pattern<T, F> or(FilterFunction<F> newFilterFunction) {
- ClosureCleaner.clean(newFilterFunction, true);
+ public Pattern<T, F> or(FilterFunction<F> orFilterFunction) {
+ ClosureCleaner.clean(orFilterFunction, true);
if (this.filterFunction == null) {
- this.filterFunction = newFilterFunction;
+ this.filterFunction = orFilterFunction;
} else {
- this.filterFunction = new OrFilterFunction<>(this.filterFunction, newFilterFunction);
+ this.filterFunction = new OrFilterFunction<>(this.filterFunction, orFilterFunction);
}
return this;