org.apache.flink.streaming.api.operators.co.CoProcessOperator Java Examples

The following examples show how to use org.apache.flink.streaming.api.operators.co.CoProcessOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessFunctionTestHarnesses.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an initialized test harness for {@link CoProcessFunction} with two input streams.
 *
 * @param function instance of a {@link CoProcessFunction} under test
 * @param <IN1> type of first input stream elements
 * @param <IN2> type of second input stream elements
 * @param <OUT> type of output stream elements
 * @return {@link TwoInputStreamOperatorTestHarness} wrapped around {@code function}
 */
public static <IN1, IN2, OUT>
TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> forCoProcessFunction(
	final CoProcessFunction<IN1, IN2, OUT> function)
	throws Exception {

	TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness =
		new TwoInputStreamOperatorTestHarness<>(
			new CoProcessOperator<>(
				Preconditions.checkNotNull(function)),
			1,
			1,
			0);
	testHarness.open();
	return testHarness;
}
 
Example #2
Source File: ConnectedStreams.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given {@link CoProcessFunction} on the connected input streams,
 * thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link #flatMap(CoFlatMapFunction)} function,
 * this function can also query the time and set timers. When reacting to the firing of set
 * timers the function can directly emit elements and/or register yet more timers.
 *
 * @param coProcessFunction The {@link CoProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code CoProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@Internal
public <R> SingleOutputStreamOperator<R> process(
		CoProcessFunction<IN1, IN2, R> coProcessFunction,
		TypeInformation<R> outputType) {

	TwoInputStreamOperator<IN1, IN2, R> operator;

	if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) {
		operator = new KeyedCoProcessOperator<>(inputStream1.clean(coProcessFunction));
	} else {
		operator = new CoProcessOperator<>(inputStream1.clean(coProcessFunction));
	}

	return transform("Co-Process", outputType, operator);
}
 
Example #3
Source File: ConnectedStreams.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given {@link CoProcessFunction} on the connected input streams,
 * thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link #flatMap(CoFlatMapFunction)} function,
 * this function can also query the time and set timers. When reacting to the firing of set
 * timers the function can directly emit elements and/or register yet more timers.
 *
 * @param coProcessFunction The {@link CoProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code CoProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@Internal
public <R> SingleOutputStreamOperator<R> process(
		CoProcessFunction<IN1, IN2, R> coProcessFunction,
		TypeInformation<R> outputType) {

	TwoInputStreamOperator<IN1, IN2, R> operator;

	if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) {
		operator = new LegacyKeyedCoProcessOperator<>(inputStream1.clean(coProcessFunction));
	} else {
		operator = new CoProcessOperator<>(inputStream1.clean(coProcessFunction));
	}

	return transform("Co-Process", outputType, operator);
}
 
Example #4
Source File: ConnectedStreams.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given {@link CoProcessFunction} on the connected input streams,
 * thereby creating a transformed output stream.
 *
 * <p>The function will be called for every element in the input streams and can produce zero
 * or more output elements. Contrary to the {@link #flatMap(CoFlatMapFunction)} function,
 * this function can also query the time and set timers. When reacting to the firing of set
 * timers the function can directly emit elements and/or register yet more timers.
 *
 * @param coProcessFunction The {@link CoProcessFunction} that is called for each element
 *                      in the stream.
 *
 * @param <R> The type of elements emitted by the {@code CoProcessFunction}.
 *
 * @return The transformed {@link DataStream}.
 */
@Internal
public <R> SingleOutputStreamOperator<R> process(
		CoProcessFunction<IN1, IN2, R> coProcessFunction,
		TypeInformation<R> outputType) {

	TwoInputStreamOperator<IN1, IN2, R> operator;

	if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) {
		operator = new LegacyKeyedCoProcessOperator<>(inputStream1.clean(coProcessFunction));
	} else {
		operator = new CoProcessOperator<>(inputStream1.clean(coProcessFunction));
	}

	return transform("Co-Process", outputType, operator);
}