forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[streaming] CoFlatMap & CoGroupReduce functionality
- Loading branch information
1 parent
1e38a63
commit 7596012
Showing
10 changed files
with
684 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ming-core/src/main/java/org/apache/flink/streaming/api/function/co/CoFlatMapFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.api.function.co; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.apache.flink.api.common.functions.Function; | ||
import org.apache.flink.util.Collector; | ||
|
||
/** | ||
* A CoFlatMapFunction represents a FlatMap transformation with two different | ||
* input types. | ||
* | ||
* @param <IN1> | ||
* Type of the first input. | ||
* @param <IN2> | ||
* Type of the second input. | ||
* @param <OUT> | ||
* Output type. | ||
*/ | ||
public interface CoFlatMapFunction<IN1, IN2, OUT> extends Function, Serializable { | ||
|
||
public void flatMap1(IN1 value, Collector<OUT> out) throws Exception; | ||
|
||
public void flatMap2(IN2 value, Collector<OUT> out) throws Exception; | ||
} |
113 changes: 113 additions & 0 deletions
113
...aming-core/src/main/java/org/apache/flink/streaming/api/function/co/CoReduceFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.api.function.co; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.apache.flink.api.common.functions.Function; | ||
|
||
/** | ||
* The CoReduceFunction interface represents a Reduce transformation with two | ||
* different input streams. The reduce1 function combine groups of elements of | ||
* the first input with the same key to a single value, while reduce2 combine | ||
* groups of elements of the second input with the same key to a single value. | ||
* Each produced values are mapped to the same type by map1 and map2, | ||
* respectively, to form one output stream. | ||
* | ||
* The basic syntax for using a grouped ReduceFunction is as follows: | ||
* | ||
* <pre> | ||
* <blockquote> | ||
* ConnectedDataStream<X> input = ...; | ||
* | ||
* ConnectedDataStream<X> result = input.groupBy(keyPosition1, keyPosition2) | ||
* .reduce(new MyCoReduceFunction(), keyPosition1, keyPosition2).addSink(...); | ||
* </blockquote> | ||
* </pre> | ||
* <p> | ||
* | ||
* @param <IN1> | ||
* Type of the first input. | ||
* @param <IN2> | ||
* Type of the second input. | ||
* @param <OUT> | ||
* Output type. | ||
*/ | ||
public interface CoReduceFunction<IN1, IN2, OUT> extends Function, Serializable { | ||
|
||
/** | ||
* The core method of CoReduceFunction, combining two values of the first | ||
* input into one value of the same type. The reduce1 function is | ||
* consecutively applied to all values of a group until only a single value | ||
* remains. | ||
* | ||
* @param value1 | ||
* The first value to combine. | ||
* @param value2 | ||
* The second value to combine. | ||
* @return The combined value of both input values. | ||
* | ||
* @throws Exception | ||
* This method may throw exceptions. Throwing an exception will | ||
* cause the operation to fail and may trigger recovery. | ||
*/ | ||
public abstract IN1 reduce1(IN1 value1, IN1 value2); | ||
|
||
/** | ||
* The core method of ReduceFunction, combining two values of the second | ||
* input into one value of the same type. The reduce2 function is | ||
* consecutively applied to all values of a group until only a single value | ||
* remains. | ||
* | ||
* @param value1 | ||
* The first value to combine. | ||
* @param value2 | ||
* The second value to combine. | ||
* @return The combined value of both input values. | ||
* | ||
* @throws Exception | ||
* This method may throw exceptions. Throwing an exception will | ||
* cause the operation to fail and may trigger recovery. | ||
*/ | ||
public abstract IN2 reduce2(IN2 value1, IN2 value2); | ||
|
||
/** | ||
* Maps the reduced first input to the output type. | ||
* | ||
* @param <IN1> | ||
* Type of the first input. | ||
* @param <IN2> | ||
* Type of the second input. | ||
* @param <OUT> | ||
* Output type. | ||
*/ | ||
public abstract OUT map1(IN1 value); | ||
|
||
/** | ||
* Maps the reduced second input to the output type. | ||
* | ||
* @param <IN1> | ||
* Type of the first input. | ||
* @param <IN2> | ||
* Type of the second input. | ||
* @param <OUT> | ||
* Output type. | ||
*/ | ||
public abstract OUT map2(IN2 value); | ||
} |
60 changes: 60 additions & 0 deletions
60
...rc/main/java/org/apache/flink/streaming/api/invokable/operator/co/CoFlatMapInvokable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.flink.streaming.api.invokable.operator.co; | ||
|
||
import org.apache.flink.api.common.functions.RichFunction; | ||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.streaming.api.function.co.CoFlatMapFunction; | ||
|
||
public class CoFlatMapInvokable<IN1, IN2, OUT> extends CoInvokable<IN1, IN2, OUT> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private CoFlatMapFunction<IN1, IN2, OUT> flatMapper; | ||
|
||
public CoFlatMapInvokable(CoFlatMapFunction<IN1, IN2, OUT> flatMapper) { | ||
super(flatMapper); | ||
this.flatMapper = flatMapper; | ||
} | ||
|
||
@Override | ||
public void handleStream1() throws Exception { | ||
flatMapper.flatMap1(reuse1.getObject(), collector); | ||
} | ||
|
||
@Override | ||
public void handleStream2() throws Exception { | ||
flatMapper.flatMap2(reuse2.getObject(), collector); | ||
} | ||
|
||
@Override | ||
public void open(Configuration parameters) throws Exception { | ||
if (flatMapper instanceof RichFunction) { | ||
((RichFunction) flatMapper).open(parameters); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
if (flatMapper instanceof RichFunction) { | ||
((RichFunction) flatMapper).close(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.