Search in sources :

Example 1 with KeyGroupStreamPartitioner

use of org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner in project flink by apache.

the class DataStreamTest method sinkKeyTest.

@Test
public void sinkKeyTest() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSink<Long> sink = env.generateSequence(1, 100).print();
    assertTrue(env.getStreamGraph().getStreamNode(sink.getTransformation().getId()).getStatePartitioner1() == null);
    assertTrue(env.getStreamGraph().getStreamNode(sink.getTransformation().getId()).getInEdges().get(0).getPartitioner() instanceof ForwardPartitioner);
    KeySelector<Long, Long> key1 = new KeySelector<Long, Long>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Long getKey(Long value) throws Exception {
            return (long) 0;
        }
    };
    DataStreamSink<Long> sink2 = env.generateSequence(1, 100).keyBy(key1).print();
    assertNotNull(env.getStreamGraph().getStreamNode(sink2.getTransformation().getId()).getStatePartitioner1());
    assertNotNull(env.getStreamGraph().getStreamNode(sink2.getTransformation().getId()).getStateKeySerializer());
    assertNotNull(env.getStreamGraph().getStreamNode(sink2.getTransformation().getId()).getStateKeySerializer());
    assertEquals(key1, env.getStreamGraph().getStreamNode(sink2.getTransformation().getId()).getStatePartitioner1());
    assertTrue(env.getStreamGraph().getStreamNode(sink2.getTransformation().getId()).getInEdges().get(0).getPartitioner() instanceof KeyGroupStreamPartitioner);
    KeySelector<Long, Long> key2 = new KeySelector<Long, Long>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Long getKey(Long value) throws Exception {
            return (long) 0;
        }
    };
    DataStreamSink<Long> sink3 = env.generateSequence(1, 100).keyBy(key2).print();
    assertTrue(env.getStreamGraph().getStreamNode(sink3.getTransformation().getId()).getStatePartitioner1() != null);
    assertEquals(key2, env.getStreamGraph().getStreamNode(sink3.getTransformation().getId()).getStatePartitioner1());
    assertTrue(env.getStreamGraph().getStreamNode(sink3.getTransformation().getId()).getInEdges().get(0).getPartitioner() instanceof KeyGroupStreamPartitioner);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) ForwardPartitioner(org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner) KeySelector(org.apache.flink.api.java.functions.KeySelector) KeyGroupStreamPartitioner(org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner) Test(org.junit.Test)

Aggregations

KeySelector (org.apache.flink.api.java.functions.KeySelector)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 ForwardPartitioner (org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner)1 KeyGroupStreamPartitioner (org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner)1 Test (org.junit.Test)1