You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by dawidwys <gi...@git.apache.org> on 2017/07/13 10:03:58 UTC

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

GitHub user dawidwys opened a pull request:

    https://github.com/apache/flink/pull/4320

    [FLINK-6244] Emit timeouted Patterns as Side Output

    Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
    If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the [How To Contribute guide](http://flink.apache.org/how-to-contribute.html).
    In addition to going through the list, please provide a meaningful description of your changes.
    
    - [ ] General
      - The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
      - The pull request addresses only one issue
      - Each commit in the PR has a meaningful commit message (including the JIRA id)
    
    - [ ] Documentation
      - Documentation has been added for new functionality
      - Old documentation affected by the pull request has been updated
      - JavaDoc for public methods has been added
    
    - [ ] Tests & Build
      - Functionality added by the pull request is covered by tests
      - `mvn clean verify` has been executed successfully locally or a Travis build has passed


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dawidwys/flink side-outputs

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/4320.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #4320
    
----
commit 2ae39185facf70ca4e394504b4ac5dc8562570a3
Author: Dawid Wysakowicz <dw...@apache.org>
Date:   2017-07-11T14:52:15Z

    [FLINK-6244] Emit timeouted Patterns as Side Output

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132446724
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java ---
    @@ -163,14 +251,34 @@
     			null,
     			false);
     
    +		final OutputTag<L> outputTag = new OutputTag<L>("dummy-timeouted", leftTypeInfo);
    +
    +		final SingleOutputStreamOperator<R> mainStream = CEPOperatorUtils.createTimeoutPatternStream(
    +			inputStream,
    +			pattern,
    +			clean(patternSelectFunction),
    +			rightTypeInfo,
    +			outputTag,
    +			clean(patternTimeoutFunction));
    +
    +		final DataStream<L> timeoutedStream = mainStream.getSideOutput(outputTag);
    +
     		TypeInformation<Either<L, R>> outTypeInfo = new EitherTypeInfo<>(leftTypeInfo, rightTypeInfo);
     
    -		return patternStream.map(
    -			new PatternSelectTimeoutMapper<>(
    -				patternStream.getExecutionEnvironment().clean(patternSelectFunction),
    -				patternStream.getExecutionEnvironment().clean(patternTimeoutFunction)
    -			)
    -		).returns(outTypeInfo);
    +		return mainStream.connect(timeoutedStream).map(new CoMapFunction<R, L, Either<L, R>>() {
    --- End diff --
    
    I think using an anonymous inner class here can be problematic because it will capture the `PatternStream` in it's closure, if I'm not mistaken.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132445956
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java ---
    @@ -125,25 +172,66 @@
     	 * partial pattern sequence the provided {@link PatternTimeoutFunction} is called. The pattern
     	 * timeout function can produce exactly one resulting element.
     	 *
    +	 * <p>You can get the stream of late data using
    --- End diff --
    
    Same as above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #4320: [FLINK-6244] Emit timeouted Patterns as Side Output

Posted by dawidwys <gi...@git.apache.org>.
Github user dawidwys commented on the issue:

    https://github.com/apache/flink/pull/4320
  
    Thanks for the review @aljoscha . I've addressed all your comments. Also changed a section in docs to use the preferred version of handling timeouted results. I've rebased the PR, as it was far behind master and there were some conflicts.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132443663
  
    --- Diff: flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/PatternStream.scala ---
    @@ -82,36 +78,54 @@ class PatternStream[T](jPatternStream: JPatternStream[T]) {
         *                               pattern sequence.
         * @tparam L Type of the resulting timeout event
         * @tparam R Type of the resulting event
    +    * @deprecated Use the version that returns timeouted events as a side-output
         * @return Data stream of either type which contains the resulting events and resulting timeout
         *         events.
         */
    +  @deprecated
       def select[L: TypeInformation, R: TypeInformation](
         patternTimeoutFunction: PatternTimeoutFunction[T, L],
         patternSelectFunction: PatternSelectFunction[T, R])
       : DataStream[Either[L, R]] = {
    +    val outputTag = OutputTag[L]("dummy-timeouted")
    --- End diff --
    
    Maybe don't use "dummy" for that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #4320: [FLINK-6244] Emit timeouted Patterns as Side Output

Posted by dawidwys <gi...@git.apache.org>.
Github user dawidwys commented on the issue:

    https://github.com/apache/flink/pull/4320
  
    I will merge it then.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by tedyu <gi...@git.apache.org>.
Github user tedyu commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r134687041
  
    --- Diff: docs/dev/libs/cep.md ---
    @@ -1279,63 +1279,75 @@ and `flatSelect` API calls allow a timeout handler to be specified. This timeout
     partial event sequence. The timeout handler receives all the events that have been matched so far by the pattern, and
     the timestamp when the timeout was detected.
     
    +In order to treat partial patterns, the `select` and `flatSelect` API calls offer an overloaded version which takes as
    +parameters
    +
    + * `PatternTimeoutFunction`/`PatternFlatTimeoutFunction`
    + * [OutputTag]({{ site.baseurl }}/dev/stream/side_output.html) for the side output in which the timeouted matches will be returned
    --- End diff --
    
    timeouted -> timed out


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by tedyu <gi...@git.apache.org>.
Github user tedyu commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r134689181
  
    --- Diff: flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/PatternStream.scala ---
    @@ -84,37 +79,54 @@ class PatternStream[T](jPatternStream: JPatternStream[T]) {
         *                               pattern sequence.
         * @tparam L Type of the resulting timeout event
         * @tparam R Type of the resulting event
    +    * @deprecated Use the version that returns timeouted events as a side-output
    --- End diff --
    
    timeouted -> timed out


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #4320: [FLINK-6244] Emit timeouted Patterns as Side Output

Posted by dawidwys <gi...@git.apache.org>.
Github user dawidwys commented on the issue:

    https://github.com/apache/flink/pull/4320
  
    R: @kl0u 
    
    @aljoscha I think it would be nice if you also had a look, as you spotted some problems with first approach to side-ouputs in CEP.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by tedyu <gi...@git.apache.org>.
Github user tedyu commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r134692117
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/operator/AbstractKeyedCEPPatternOperator.java ---
    @@ -348,7 +353,18 @@ private void updateNFA(NFA<IN> nfa) throws IOException {
     	 * @param event The current event to be processed
     	 * @param timestamp The timestamp of the event
     	 */
    -	protected abstract void processEvent(NFA<IN> nfa, IN event, long timestamp);
    +	private void processEvent(NFA<IN> nfa, IN event, long timestamp)  {
    +		Tuple2<Collection<Map<String, List<IN>>>, Collection<Tuple2<Map<String, List<IN>>, Long>>> patterns =
    +			nfa.process(event, timestamp);
    +
    +		try {
    +			processMatchedSequences(patterns.f0, timestamp);
    --- End diff --
    
    processMatchedSequences -> processMatchingSequences


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #4320: [FLINK-6244] Emit timeouted Patterns as Side Output

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on the issue:

    https://github.com/apache/flink/pull/4320
  
    To me, this looks good now. Let's see if @kl0u want's to take another look, otherwise I would say it's good to merge.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/flink/pull/4320


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132446221
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java ---
    @@ -213,14 +321,97 @@
     	 * @return {@link DataStream} which contains the resulting elements from the pattern flat select
     	 *         function.
     	 */
    -	public <R> SingleOutputStreamOperator<R> flatSelect(final PatternFlatSelectFunction<T, R> patternFlatSelectFunction, TypeInformation<R> outTypeInfo) {
    -		SingleOutputStreamOperator<Map<String, List<T>>> patternStream =
    -				CEPOperatorUtils.createPatternStream(inputStream, pattern);
    -
    -		return patternStream.flatMap(
    -			new PatternFlatSelectMapper<>(
    -				patternStream.getExecutionEnvironment().clean(patternFlatSelectFunction)
    -			)).returns(outTypeInfo);
    +	public <R> SingleOutputStreamOperator<R> flatSelect(
    +			final PatternFlatSelectFunction<T, R> patternFlatSelectFunction,
    +			final TypeInformation<R> outTypeInfo) {
    +		return CEPOperatorUtils.createPatternStream(
    +			inputStream,
    +			pattern,
    +			clean(patternFlatSelectFunction),
    +			outTypeInfo);
    +	}
    +
    +	/**
    +	 * Applies a flat select function to the detected pattern sequence. For each pattern sequence the
    +	 * provided {@link PatternFlatSelectFunction} is called. The pattern select function can produce
    +	 * exactly one resulting element.
    +	 *
    +	 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
    +	 * partial pattern sequence the provided {@link PatternFlatTimeoutFunction} is called. The pattern
    +	 * timeout function can produce exactly one resulting element.
    +	 *
    +	 * <p>You can get the stream of late data using
    +	 * {@link SingleOutputStreamOperator#getSideOutput(OutputTag)} on the
    +	 * {@link SingleOutputStreamOperator} resulting from the select operation
    +	 * with the same {@link OutputTag}.
    +	 *
    +	 * @param timeoutOutputTag {@link OutputTag} that identifies side output with timeouted patterns
    +	 * @param patternFlatTimeoutFunction The pattern timeout function which is called for each partial
    +	 *                               pattern sequence which has timed out.
    +	 * @param patternFlatSelectFunction The pattern select function which is called for each detected
    +	 *                              pattern sequence.
    +	 * @param <L> Type of the resulting timeout elements
    +	 * @param <R> Type of the resulting elements
    +	 * @return {@link DataStream} which contains the resulting elements with the resulting timeout
    +	 * elements in a side output.
    +	 */
    +	public <L, R> SingleOutputStreamOperator<R> flatSelect(
    +		final OutputTag<L> timeoutOutputTag,
    +		final PatternFlatTimeoutFunction<T, L> patternFlatTimeoutFunction,
    +		final PatternFlatSelectFunction<T, R> patternFlatSelectFunction) {
    +
    +		TypeInformation<R> rightTypeInfo = TypeExtractor.getUnaryOperatorReturnType(
    +			patternFlatSelectFunction,
    +			PatternFlatSelectFunction.class,
    +			0,
    +			1,
    +			new int[]{0, 1, 0},
    +			new int[]{1, 0},
    +			inputStream.getType(),
    +			null,
    +			false);
    +
    +		return flatSelect(timeoutOutputTag, patternFlatTimeoutFunction, rightTypeInfo, patternFlatSelectFunction);
    +	}
    +
    +	/**
    +	 * Applies a flat select function to the detected pattern sequence. For each pattern sequence the
    +	 * provided {@link PatternFlatSelectFunction} is called. The pattern select function can produce
    +	 * exactly one resulting element.
    +	 *
    +	 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
    +	 * partial pattern sequence the provided {@link PatternFlatTimeoutFunction} is called. The pattern
    +	 * timeout function can produce exactly one resulting element.
    +	 *
    +	 * <p>You can get the stream of late data using
    --- End diff --
    
    Same as above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132445880
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java ---
    @@ -107,13 +113,54 @@
     	 *         function.
     	 */
     	public <R> SingleOutputStreamOperator<R> select(final PatternSelectFunction<T, R> patternSelectFunction, TypeInformation<R> outTypeInfo) {
    -		SingleOutputStreamOperator<Map<String, List<T>>> patternStream =
    -				CEPOperatorUtils.createPatternStream(inputStream, pattern);
    +		return CEPOperatorUtils.createPatternStream(inputStream, pattern, clean(patternSelectFunction), outTypeInfo);
    +	}
    +
    +	/**
    +	 * Applies a select function to the detected pattern sequence. For each pattern sequence the
    +	 * provided {@link PatternSelectFunction} is called. The pattern select function can produce
    +	 * exactly one resulting element.
    +	 *
    +	 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
    +	 * partial pattern sequence the provided {@link PatternTimeoutFunction} is called. The pattern
    +	 * timeout function can produce exactly one resulting element.
    +	 *
    +	 * <p>You can get the stream of late data using
    --- End diff --
    
    Maybe something like "You can get the stream of timed-out data resulting from the {@link PatternTimeoutFunction} using ..."


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by tedyu <gi...@git.apache.org>.
Github user tedyu commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r134692032
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/operator/AbstractKeyedCEPPatternOperator.java ---
    @@ -348,7 +353,18 @@ private void updateNFA(NFA<IN> nfa) throws IOException {
     	 * @param event The current event to be processed
     	 * @param timestamp The timestamp of the event
     	 */
    -	protected abstract void processEvent(NFA<IN> nfa, IN event, long timestamp);
    +	private void processEvent(NFA<IN> nfa, IN event, long timestamp)  {
    +		Tuple2<Collection<Map<String, List<IN>>>, Collection<Tuple2<Map<String, List<IN>>, Long>>> patterns =
    +			nfa.process(event, timestamp);
    +
    +		try {
    +			processMatchedSequences(patterns.f0, timestamp);
    +			processTimeoutedSequence(patterns.f1, timestamp);
    --- End diff --
    
    processTimeoutedSequence -> processTimedoutSequence


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #4320: [FLINK-6244] Emit timeouted Patterns as Side Outpu...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4320#discussion_r132446175
  
    --- Diff: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java ---
    @@ -213,14 +321,97 @@
     	 * @return {@link DataStream} which contains the resulting elements from the pattern flat select
     	 *         function.
     	 */
    -	public <R> SingleOutputStreamOperator<R> flatSelect(final PatternFlatSelectFunction<T, R> patternFlatSelectFunction, TypeInformation<R> outTypeInfo) {
    -		SingleOutputStreamOperator<Map<String, List<T>>> patternStream =
    -				CEPOperatorUtils.createPatternStream(inputStream, pattern);
    -
    -		return patternStream.flatMap(
    -			new PatternFlatSelectMapper<>(
    -				patternStream.getExecutionEnvironment().clean(patternFlatSelectFunction)
    -			)).returns(outTypeInfo);
    +	public <R> SingleOutputStreamOperator<R> flatSelect(
    +			final PatternFlatSelectFunction<T, R> patternFlatSelectFunction,
    +			final TypeInformation<R> outTypeInfo) {
    +		return CEPOperatorUtils.createPatternStream(
    +			inputStream,
    +			pattern,
    +			clean(patternFlatSelectFunction),
    +			outTypeInfo);
    +	}
    +
    +	/**
    +	 * Applies a flat select function to the detected pattern sequence. For each pattern sequence the
    +	 * provided {@link PatternFlatSelectFunction} is called. The pattern select function can produce
    +	 * exactly one resulting element.
    +	 *
    +	 * <p>Applies a timeout function to a partial pattern sequence which has timed out. For each
    +	 * partial pattern sequence the provided {@link PatternFlatTimeoutFunction} is called. The pattern
    +	 * timeout function can produce exactly one resulting element.
    +	 *
    +	 * <p>You can get the stream of late data using
    --- End diff --
    
    Same as above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---