Search in sources :

Example 1 with ProcessJoinFunction

use of org.apache.flink.streaming.api.functions.co.ProcessJoinFunction in project flink by apache.

the class IntervalJoinITCase method testCanJoinOverSameKey.

@Test
public void testCanJoinOverSameKey() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    KeyedStream<Tuple2<String, Integer>, String> streamOne = env.fromElements(Tuple2.of("key", 0), Tuple2.of("key", 1), Tuple2.of("key", 2), Tuple2.of("key", 3), Tuple2.of("key", 4), Tuple2.of("key", 5)).assignTimestampsAndWatermarks(new AscendingTuple2TimestampExtractor()).keyBy(new Tuple2KeyExtractor());
    KeyedStream<Tuple2<String, Integer>, String> streamTwo = env.fromElements(Tuple2.of("key", 0), Tuple2.of("key", 1), Tuple2.of("key", 2), Tuple2.of("key", 3), Tuple2.of("key", 4), Tuple2.of("key", 5)).assignTimestampsAndWatermarks(new AscendingTuple2TimestampExtractor()).keyBy(new Tuple2KeyExtractor());
    streamOne.intervalJoin(streamTwo).between(Time.milliseconds(0), Time.milliseconds(0)).process(new ProcessJoinFunction<Tuple2<String, Integer>, Tuple2<String, Integer>, String>() {

        @Override
        public void processElement(Tuple2<String, Integer> left, Tuple2<String, Integer> right, Context ctx, Collector<String> out) throws Exception {
            out.collect(left + ":" + right);
        }
    }).addSink(new ResultSink());
    env.execute();
    expectInAnyOrder("(key,0):(key,0)", "(key,1):(key,1)", "(key,2):(key,2)", "(key,3):(key,3)", "(key,4):(key,4)", "(key,5):(key,5)");
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) ProcessJoinFunction(org.apache.flink.streaming.api.functions.co.ProcessJoinFunction) Collector(org.apache.flink.util.Collector) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 ProcessJoinFunction (org.apache.flink.streaming.api.functions.co.ProcessJoinFunction)1 Collector (org.apache.flink.util.Collector)1 Test (org.junit.Test)1