use of org.apache.flink.streaming.api.transformations.KeyedMultipleInputTransformation in project flink by apache.
the class MultipleInputITCase method testKeyedState.
@Test
public void testKeyedState() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
TestListResultSink<Long> resultSink = new TestListResultSink<>();
DataStream<Long> source1 = env.fromElements(0L, 3L);
DataStream<Long> source2 = env.fromElements(13L, 16L);
DataStream<Long> source3 = env.fromElements(101L, 104L);
KeyedMultipleInputTransformation<Long> transform = new KeyedMultipleInputTransformation<>("My Operator", new KeyedSumMultipleInputOperatorFactory(), BasicTypeInfo.LONG_TYPE_INFO, 1, BasicTypeInfo.LONG_TYPE_INFO);
KeySelector<Long, Long> keySelector = (KeySelector<Long, Long>) value -> value % 3;
env.addOperator(transform.addInput(source1.getTransformation(), keySelector).addInput(source2.getTransformation(), keySelector).addInput(source3.getTransformation(), keySelector));
new MultipleConnectedStreams(env).transform(transform).addSink(resultSink);
env.execute();
List<Long> result = resultSink.getResult();
Collections.sort(result);
assertThat(result, contains(0L, 3L, 13L, 13L + 16L, 101L, 101L + 104L));
}
Aggregations