org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction Java Examples
The following examples show how to use
org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.
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: ConnectedStreams.java From flink with Apache License 2.0 | 6 votes |
/** * Applies the given {@link KeyedCoProcessFunction} on the connected input keyed streams, * thereby creating a transformed output stream. * * <p>The function will be called for every element in the input keyed 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 keyedCoProcessFunction The {@link KeyedCoProcessFunction} 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}. */ @PublicEvolving public <K, R> SingleOutputStreamOperator<R> process( KeyedCoProcessFunction<K, IN1, IN2, R> keyedCoProcessFunction) { TypeInformation<R> outTypeInfo = TypeExtractor.getBinaryOperatorReturnType( keyedCoProcessFunction, KeyedCoProcessFunction.class, 1, 2, 3, TypeExtractor.NO_INDEX, getType1(), getType2(), Utils.getCallLocationName(), true); return process(keyedCoProcessFunction, outTypeInfo); }
Example #2
Source File: ConnectedStreams.java From flink with Apache License 2.0 | 6 votes |
/** * Applies the given {@link KeyedCoProcessFunction} 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 keyedCoProcessFunction The {@link KeyedCoProcessFunction} 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 <K, R> SingleOutputStreamOperator<R> process( KeyedCoProcessFunction<K, IN1, IN2, R> keyedCoProcessFunction, TypeInformation<R> outputType) { TwoInputStreamOperator<IN1, IN2, R> operator; if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) { operator = new KeyedCoProcessOperator<>(inputStream1.clean(keyedCoProcessFunction)); } else { throw new UnsupportedOperationException("KeyedCoProcessFunction can only be used " + "when both input streams are of type KeyedStream."); } return transform("Co-Keyed-Process", outputType, operator); }
Example #3
Source File: ConnectedStreams.java From flink with Apache License 2.0 | 6 votes |
/** * Applies the given {@link KeyedCoProcessFunction} on the connected input keyed streams, * thereby creating a transformed output stream. * * <p>The function will be called for every element in the input keyed 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 keyedCoProcessFunction The {@link KeyedCoProcessFunction} 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}. */ @PublicEvolving public <K, R> SingleOutputStreamOperator<R> process( KeyedCoProcessFunction<K, IN1, IN2, R> keyedCoProcessFunction) { TypeInformation<R> outTypeInfo = TypeExtractor.getBinaryOperatorReturnType( keyedCoProcessFunction, KeyedCoProcessFunction.class, 1, 2, 3, TypeExtractor.NO_INDEX, getType1(), getType2(), Utils.getCallLocationName(), true); return process(keyedCoProcessFunction, outTypeInfo); }
Example #4
Source File: ConnectedStreams.java From flink with Apache License 2.0 | 6 votes |
/** * Applies the given {@link KeyedCoProcessFunction} 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 keyedCoProcessFunction The {@link KeyedCoProcessFunction} 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 <K, R> SingleOutputStreamOperator<R> process( KeyedCoProcessFunction<K, IN1, IN2, R> keyedCoProcessFunction, TypeInformation<R> outputType) { TwoInputStreamOperator<IN1, IN2, R> operator; if ((inputStream1 instanceof KeyedStream) && (inputStream2 instanceof KeyedStream)) { operator = new KeyedCoProcessOperator<>(inputStream1.clean(keyedCoProcessFunction)); } else { throw new UnsupportedOperationException("KeyedCoProcessFunction can only be used " + "when both input streams are of type KeyedStream."); } return transform("Co-Keyed-Process", outputType, operator); }
Example #5
Source File: ProcessFunctionTestHarnesses.java From flink with Apache License 2.0 | 6 votes |
/** * Returns an initialized test harness for {@link KeyedCoProcessFunction} with two input streams. * * @param function instance of a {@link KeyedCoProcessFunction} under test * @param <K> key type * @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 KeyedOneInputStreamOperatorTestHarness} wrapped around {@code function} */ public static <K, IN1, IN2, OUT> KeyedTwoInputStreamOperatorTestHarness<K, IN1, IN2, OUT> forKeyedCoProcessFunction( final KeyedCoProcessFunction<K, IN1, IN2, OUT> function, final KeySelector<IN1, K> keySelector1, final KeySelector<IN2, K> keySelector2, final TypeInformation<K> keyType) throws Exception { KeyedTwoInputStreamOperatorTestHarness<K, IN1, IN2, OUT> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( new KeyedCoProcessOperator<>(Preconditions.checkNotNull(function)), keySelector1, keySelector2, keyType, 1, 1, 0); testHarness.open(); return testHarness; }
Example #6
Source File: KeyedCoProcessOperatorWithWatermarkDelay.java From flink with Apache License 2.0 | 5 votes |
public KeyedCoProcessOperatorWithWatermarkDelay(KeyedCoProcessFunction<K, IN1, IN2, OUT> flatMapper, long watermarkDelay) { super(flatMapper); Preconditions.checkArgument(watermarkDelay >= 0, "The watermark delay should be non-negative."); if (watermarkDelay == 0) { // emits watermark without delay emitter = (Consumer<Watermark> & Serializable) (Watermark mark) -> output.emitWatermark(mark); } else { // emits watermark with delay emitter = (Consumer<Watermark> & Serializable) (Watermark mark) -> output .emitWatermark(new Watermark(mark.getTimestamp() - watermarkDelay)); } }
Example #7
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
public KeyedCoProcessOperator(KeyedCoProcessFunction<K, IN1, IN2, OUT> keyedCoProcessFunction) { super(keyedCoProcessFunction); }
Example #8
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
ContextImpl(KeyedCoProcessFunction<K, IN1, IN2, OUT> function, TimerService timerService) { function.super(); this.timerService = checkNotNull(timerService); }
Example #9
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
OnTimerContextImpl(KeyedCoProcessFunction<K, IN1, IN2, OUT> function, TimerService timerService) { function.super(); this.timerService = checkNotNull(timerService); }
Example #10
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
public KeyedCoProcessOperator(KeyedCoProcessFunction<K, IN1, IN2, OUT> keyedCoProcessFunction) { super(keyedCoProcessFunction); }
Example #11
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
ContextImpl(KeyedCoProcessFunction<K, IN1, IN2, OUT> function, TimerService timerService) { function.super(); this.timerService = checkNotNull(timerService); }
Example #12
Source File: KeyedCoProcessOperator.java From flink with Apache License 2.0 | 4 votes |
OnTimerContextImpl(KeyedCoProcessFunction<K, IN1, IN2, OUT> function, TimerService timerService) { function.super(); this.timerService = checkNotNull(timerService); }