org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner Java Examples
The following examples show how to use
org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner.
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: StreamGraphHasherV2.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private boolean isChainable(StreamEdge edge, boolean isChainingEnabled, StreamGraph streamGraph) { StreamNode upStreamVertex = streamGraph.getSourceVertex(edge); StreamNode downStreamVertex = streamGraph.getTargetVertex(edge); StreamOperator<?> headOperator = upStreamVertex.getOperator(); StreamOperator<?> outOperator = downStreamVertex.getOperator(); return downStreamVertex.getInEdges().size() == 1 && outOperator != null && headOperator != null && upStreamVertex.isSameSlotSharingGroup(downStreamVertex) && outOperator.getChainingStrategy() == ChainingStrategy.ALWAYS && (headOperator.getChainingStrategy() == ChainingStrategy.HEAD || headOperator.getChainingStrategy() == ChainingStrategy.ALWAYS) && (edge.getPartitioner() instanceof ForwardPartitioner) && upStreamVertex.getParallelism() == downStreamVertex.getParallelism() && isChainingEnabled; }
Example #2
Source File: StreamingJobGraphGenerator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static boolean isChainable(StreamEdge edge, StreamGraph streamGraph) { StreamNode upStreamVertex = streamGraph.getSourceVertex(edge); StreamNode downStreamVertex = streamGraph.getTargetVertex(edge); StreamOperator<?> headOperator = upStreamVertex.getOperator(); StreamOperator<?> outOperator = downStreamVertex.getOperator(); return downStreamVertex.getInEdges().size() == 1 && outOperator != null && headOperator != null && upStreamVertex.isSameSlotSharingGroup(downStreamVertex) && outOperator.getChainingStrategy() == ChainingStrategy.ALWAYS && (headOperator.getChainingStrategy() == ChainingStrategy.HEAD || headOperator.getChainingStrategy() == ChainingStrategy.ALWAYS) && (edge.getPartitioner() instanceof ForwardPartitioner) && upStreamVertex.getParallelism() == downStreamVertex.getParallelism() && streamGraph.isChainingEnabled(); }
Example #3
Source File: DataStreamUtils.java From flink with Apache License 2.0 | 6 votes |
/** * Reinterprets the given {@link DataStream} as a {@link KeyedStream}, which extracts keys with the given * {@link KeySelector}. * * <p>IMPORTANT: For every partition of the base stream, the keys of events in the base stream must be * partitioned exactly in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * * @param stream The data stream to reinterpret. For every partition, this stream must be partitioned exactly * in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * @param keySelector Function that defines how keys are extracted from the data stream. * @param typeInfo Explicit type information about the key type. * @param <T> Type of events in the data stream. * @param <K> Type of the extracted keys. * @return The reinterpretation of the {@link DataStream} as a {@link KeyedStream}. */ public static <T, K> KeyedStream<T, K> reinterpretAsKeyedStream( DataStream<T> stream, KeySelector<T, K> keySelector, TypeInformation<K> typeInfo) { PartitionTransformation<T> partitionTransformation = new PartitionTransformation<>( stream.getTransformation(), new ForwardPartitioner<>()); return new KeyedStream<>( stream, partitionTransformation, keySelector, typeInfo); }
Example #4
Source File: StreamingJobGraphGeneratorWithGlobalDataExchangeModeTest.java From flink with Apache License 2.0 | 6 votes |
/** * Topology: source(parallelism=1) --(forward)--> map1(parallelism=1) * --(rescale)--> map2(parallelism=2) --(rebalance)--> sink(parallelism=2). */ private static StreamGraph createStreamGraph() { final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); final DataStream<Integer> source = env.fromElements(1, 2, 3).setParallelism(1); final DataStream<Integer> forward = new DataStream<>(env, new PartitionTransformation<>( source.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.UNDEFINED)); final DataStream<Integer> map1 = forward.map(i -> i).startNewChain().setParallelism(1); final DataStream<Integer> rescale = new DataStream<>(env, new PartitionTransformation<>( map1.getTransformation(), new RescalePartitioner<>(), ShuffleMode.UNDEFINED)); final DataStream<Integer> map2 = rescale.map(i -> i).setParallelism(2); map2.rebalance().print().setParallelism(2); return env.getStreamGraph(); }
Example #5
Source File: StreamGraphHasherV2.java From flink with Apache License 2.0 | 6 votes |
private boolean isChainable(StreamEdge edge, boolean isChainingEnabled, StreamGraph streamGraph) { StreamNode upStreamVertex = streamGraph.getSourceVertex(edge); StreamNode downStreamVertex = streamGraph.getTargetVertex(edge); StreamOperatorFactory<?> headOperator = upStreamVertex.getOperatorFactory(); StreamOperatorFactory<?> outOperator = downStreamVertex.getOperatorFactory(); return downStreamVertex.getInEdges().size() == 1 && outOperator != null && headOperator != null && upStreamVertex.isSameSlotSharingGroup(downStreamVertex) && outOperator.getChainingStrategy() == ChainingStrategy.ALWAYS && (headOperator.getChainingStrategy() == ChainingStrategy.HEAD || headOperator.getChainingStrategy() == ChainingStrategy.ALWAYS) && (edge.getPartitioner() instanceof ForwardPartitioner) && upStreamVertex.getParallelism() == downStreamVertex.getParallelism() && isChainingEnabled; }
Example #6
Source File: StreamingJobGraphGeneratorWithGlobalDataExchangeModeTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testGlobalDataExchangeModeDoesNotOverrideSpecifiedShuffleMode() { final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); final DataStream<Integer> source = env.fromElements(1, 2, 3).setParallelism(1); final DataStream<Integer> forward = new DataStream<>(env, new PartitionTransformation<>( source.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.PIPELINED)); forward.map(i -> i).startNewChain().setParallelism(1); final StreamGraph streamGraph = env.getStreamGraph(); streamGraph.setGlobalDataExchangeMode(GlobalDataExchangeMode.ALL_EDGES_BLOCKING); final JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(streamGraph); final List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); final JobVertex sourceVertex = verticesSorted.get(0); assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceVertex.getProducedDataSets().get(0).getResultType()); }
Example #7
Source File: StreamingJobGraphGenerator.java From flink with Apache License 2.0 | 6 votes |
public static boolean isChainable(StreamEdge edge, StreamGraph streamGraph) { StreamNode upStreamVertex = streamGraph.getSourceVertex(edge); StreamNode downStreamVertex = streamGraph.getTargetVertex(edge); StreamOperatorFactory<?> headOperator = upStreamVertex.getOperatorFactory(); StreamOperatorFactory<?> outOperator = downStreamVertex.getOperatorFactory(); return downStreamVertex.getInEdges().size() == 1 && outOperator != null && headOperator != null && upStreamVertex.isSameSlotSharingGroup(downStreamVertex) && outOperator.getChainingStrategy() == ChainingStrategy.ALWAYS && (headOperator.getChainingStrategy() == ChainingStrategy.HEAD || headOperator.getChainingStrategy() == ChainingStrategy.ALWAYS) && (edge.getPartitioner() instanceof ForwardPartitioner) && edge.getShuffleMode() != ShuffleMode.BATCH && upStreamVertex.getParallelism() == downStreamVertex.getParallelism() && streamGraph.isChainingEnabled(); }
Example #8
Source File: StreamingJobGraphGenerator.java From flink with Apache License 2.0 | 6 votes |
private ResultPartitionType determineResultPartitionType(StreamPartitioner<?> partitioner) { switch (streamGraph.getGlobalDataExchangeMode()) { case ALL_EDGES_BLOCKING: return ResultPartitionType.BLOCKING; case FORWARD_EDGES_PIPELINED: if (partitioner instanceof ForwardPartitioner) { return ResultPartitionType.PIPELINED_BOUNDED; } else { return ResultPartitionType.BLOCKING; } case POINTWISE_EDGES_PIPELINED: if (isPointwisePartitioner(partitioner)) { return ResultPartitionType.PIPELINED_BOUNDED; } else { return ResultPartitionType.BLOCKING; } case ALL_EDGES_PIPELINED: return ResultPartitionType.PIPELINED_BOUNDED; default: throw new RuntimeException("Unrecognized global data exchange mode " + streamGraph.getGlobalDataExchangeMode()); } }
Example #9
Source File: DataStreamUtils.java From flink with Apache License 2.0 | 6 votes |
/** * Reinterprets the given {@link DataStream} as a {@link KeyedStream}, which extracts keys with the given * {@link KeySelector}. * * <p>IMPORTANT: For every partition of the base stream, the keys of events in the base stream must be * partitioned exactly in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * * @param stream The data stream to reinterpret. For every partition, this stream must be partitioned exactly * in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * @param keySelector Function that defines how keys are extracted from the data stream. * @param typeInfo Explicit type information about the key type. * @param <T> Type of events in the data stream. * @param <K> Type of the extracted keys. * @return The reinterpretation of the {@link DataStream} as a {@link KeyedStream}. */ public static <T, K> KeyedStream<T, K> reinterpretAsKeyedStream( DataStream<T> stream, KeySelector<T, K> keySelector, TypeInformation<K> typeInfo) { PartitionTransformation<T> partitionTransformation = new PartitionTransformation<>( stream.getTransformation(), new ForwardPartitioner<>()); return new KeyedStream<>( stream, partitionTransformation, keySelector, typeInfo); }
Example #10
Source File: DataStreamUtils.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Reinterprets the given {@link DataStream} as a {@link KeyedStream}, which extracts keys with the given * {@link KeySelector}. * * <p>IMPORTANT: For every partition of the base stream, the keys of events in the base stream must be * partitioned exactly in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * * @param stream The data stream to reinterpret. For every partition, this stream must be partitioned exactly * in the same way as if it was created through a {@link DataStream#keyBy(KeySelector)}. * @param keySelector Function that defines how keys are extracted from the data stream. * @param typeInfo Explicit type information about the key type. * @param <T> Type of events in the data stream. * @param <K> Type of the extracted keys. * @return The reinterpretation of the {@link DataStream} as a {@link KeyedStream}. */ public static <T, K> KeyedStream<T, K> reinterpretAsKeyedStream( DataStream<T> stream, KeySelector<T, K> keySelector, TypeInformation<K> typeInfo) { PartitionTransformation<T> partitionTransformation = new PartitionTransformation<>( stream.getTransformation(), new ForwardPartitioner<>()); return new KeyedStream<>( stream, partitionTransformation, keySelector, typeInfo); }
Example #11
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#UNDEFINED}. */ @Test public void testShuffleModeUndefined() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.UNDEFINED)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.UNDEFINED)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(2, verticesSorted.size()); // it can be chained with UNDEFINED shuffle mode JobVertex sourceAndMapVertex = verticesSorted.get(0); // UNDEFINED shuffle mode is translated into PIPELINED_BOUNDED result partition by default assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceAndMapVertex.getProducedDataSets().get(0).getResultType()); }
Example #12
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#UNDEFINED}. */ @Test public void testShuffleModeUndefined() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.UNDEFINED)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.UNDEFINED)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(2, verticesSorted.size()); // it can be chained with UNDEFINED shuffle mode JobVertex sourceAndMapVertex = verticesSorted.get(0); // UNDEFINED shuffle mode is translated into PIPELINED_BOUNDED result partition by default assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceAndMapVertex.getProducedDataSets().get(0).getResultType()); }
Example #13
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#BATCH}. */ @Test public void testShuffleModeBatch() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.BATCH)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.BATCH)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(3, verticesSorted.size()); // it can not be chained with BATCH shuffle mode JobVertex sourceVertex = verticesSorted.get(0); JobVertex mapVertex = verticesSorted.get(1); // BATCH shuffle mode is translated into BLOCKING result partition assertEquals(ResultPartitionType.BLOCKING, sourceVertex.getProducedDataSets().get(0).getResultType()); assertEquals(ResultPartitionType.BLOCKING, mapVertex.getProducedDataSets().get(0).getResultType()); }
Example #14
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#PIPELINED}. */ @Test public void testShuffleModePipelined() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.PIPELINED)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.PIPELINED)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(2, verticesSorted.size()); // it can be chained with PIPELINED shuffle mode JobVertex sourceAndMapVertex = verticesSorted.get(0); // PIPELINED shuffle mode is translated into PIPELINED_BOUNDED result partition assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceAndMapVertex.getProducedDataSets().get(0).getResultType()); }
Example #15
Source File: StreamingJobGraphGenerator.java From flink with Apache License 2.0 | 5 votes |
public static boolean isChainable(StreamEdge edge, StreamGraph streamGraph) { StreamNode upStreamVertex = streamGraph.getSourceVertex(edge); StreamNode downStreamVertex = streamGraph.getTargetVertex(edge); return downStreamVertex.getInEdges().size() == 1 && upStreamVertex.isSameSlotSharingGroup(downStreamVertex) && areOperatorsChainable(upStreamVertex, downStreamVertex, streamGraph) && (edge.getPartitioner() instanceof ForwardPartitioner) && edge.getShuffleMode() != ShuffleMode.BATCH && upStreamVertex.getParallelism() == downStreamVertex.getParallelism() && streamGraph.isChainingEnabled(); }
Example #16
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test enabling the property "blockingConnectionsBetweenChains". */ @Test public void testBlockingConnectionsBetweenChainsEnabled() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Filter -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); // partition transformation with an undefined shuffle mode between source and filter DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.UNDEFINED)); DataStream<Integer> filterDataStream = partitionAfterSourceDataStream.filter(value -> true).setParallelism(2); DataStream<Integer> partitionAfterFilterDataStream = new DataStream<>(env, new PartitionTransformation<>( filterDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.UNDEFINED)); partitionAfterFilterDataStream.map(value -> value).setParallelism(2); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( filterDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.PIPELINED)); partitionAfterMapDataStream.print().setParallelism(1); StreamGraph streamGraph = env.getStreamGraph(); streamGraph.setBlockingConnectionsBetweenChains(true); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(streamGraph); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(3, verticesSorted.size()); JobVertex sourceVertex = verticesSorted.get(0); // still can be chained JobVertex filterAndMapVertex = verticesSorted.get(1); JobVertex printVertex = verticesSorted.get(2); // the edge with undefined shuffle mode is translated into BLOCKING assertEquals(ResultPartitionType.BLOCKING, sourceVertex.getProducedDataSets().get(0).getResultType()); // the edge with PIPELINED shuffle mode is translated into PIPELINED_BOUNDED assertEquals(ResultPartitionType.PIPELINED_BOUNDED, filterAndMapVertex.getProducedDataSets().get(0).getResultType()); assertEquals(ResultPartitionType.PIPELINED_BOUNDED, printVertex.getInputs().get(0).getSource().getResultType()); }
Example #17
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that "blockingConnectionsBetweenChains" is off by default. */ @Test public void testBlockingAfterChainingOffDisabled() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Filter -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); // partition transformation with an undefined shuffle mode between source and filter DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.UNDEFINED)); DataStream<Integer> filterDataStream = partitionAfterSourceDataStream.filter(value -> true).setParallelism(2); DataStream<Integer> partitionAfterFilterDataStream = new DataStream<>(env, new PartitionTransformation<>( filterDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.UNDEFINED)); partitionAfterFilterDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(2, verticesSorted.size()); JobVertex sourceVertex = verticesSorted.get(0); JobVertex filterAndPrintVertex = verticesSorted.get(1); assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceVertex.getProducedDataSets().get(0).getResultType()); assertEquals(ResultPartitionType.PIPELINED_BOUNDED, filterAndPrintVertex.getInputs().get(0).getSource().getResultType()); }
Example #18
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#BATCH}. */ @Test public void testShuffleModeBatch() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.BATCH)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.BATCH)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(3, verticesSorted.size()); // it can not be chained with BATCH shuffle mode JobVertex sourceVertex = verticesSorted.get(0); JobVertex mapVertex = verticesSorted.get(1); // BATCH shuffle mode is translated into BLOCKING result partition assertEquals(ResultPartitionType.BLOCKING, sourceVertex.getProducedDataSets().get(0).getResultType()); assertEquals(ResultPartitionType.BLOCKING, mapVertex.getProducedDataSets().get(0).getResultType()); }
Example #19
Source File: StreamingJobGraphGeneratorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Test setting shuffle mode to {@link ShuffleMode#PIPELINED}. */ @Test public void testShuffleModePipelined() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // fromElements -> Map -> Print DataStream<Integer> sourceDataStream = env.fromElements(1, 2, 3); DataStream<Integer> partitionAfterSourceDataStream = new DataStream<>(env, new PartitionTransformation<>( sourceDataStream.getTransformation(), new ForwardPartitioner<>(), ShuffleMode.PIPELINED)); DataStream<Integer> mapDataStream = partitionAfterSourceDataStream.map(value -> value).setParallelism(1); DataStream<Integer> partitionAfterMapDataStream = new DataStream<>(env, new PartitionTransformation<>( mapDataStream.getTransformation(), new RescalePartitioner<>(), ShuffleMode.PIPELINED)); partitionAfterMapDataStream.print().setParallelism(2); JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph()); List<JobVertex> verticesSorted = jobGraph.getVerticesSortedTopologicallyFromSources(); assertEquals(2, verticesSorted.size()); // it can be chained with PIPELINED shuffle mode JobVertex sourceAndMapVertex = verticesSorted.get(0); // PIPELINED shuffle mode is translated into PIPELINED_BOUNDED result partition assertEquals(ResultPartitionType.PIPELINED_BOUNDED, sourceAndMapVertex.getProducedDataSets().get(0).getResultType()); }
Example #20
Source File: StreamingJobGraphGenerator.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void connect(Integer headOfChain, StreamEdge edge) { physicalEdgesInOrder.add(edge); Integer downStreamvertexID = edge.getTargetId(); JobVertex headVertex = jobVertices.get(headOfChain); JobVertex downStreamVertex = jobVertices.get(downStreamvertexID); StreamConfig downStreamConfig = new StreamConfig(downStreamVertex.getConfiguration()); downStreamConfig.setNumberOfInputs(downStreamConfig.getNumberOfInputs() + 1); StreamPartitioner<?> partitioner = edge.getPartitioner(); JobEdge jobEdge; if (partitioner instanceof ForwardPartitioner || partitioner instanceof RescalePartitioner) { jobEdge = downStreamVertex.connectNewDataSetAsInput( headVertex, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED_BOUNDED); } else { jobEdge = downStreamVertex.connectNewDataSetAsInput( headVertex, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED_BOUNDED); } // set strategy name so that web interface can show it. jobEdge.setShipStrategyName(partitioner.toString()); if (LOG.isDebugEnabled()) { LOG.debug("CONNECTED: {} - {} -> {}", partitioner.getClass().getSimpleName(), headOfChain, downStreamvertexID); } }
Example #21
Source File: StreamingJobGraphGenerator.java From flink with Apache License 2.0 | 4 votes |
private static boolean isPointwisePartitioner(StreamPartitioner<?> partitioner) { return partitioner instanceof ForwardPartitioner || partitioner instanceof RescalePartitioner; }
Example #22
Source File: DataStreamTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testChannelSelectors() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStreamSource<Long> src = env.generateSequence(0, 0); DataStream<Long> broadcast = src.broadcast(); DataStreamSink<Long> broadcastSink = broadcast.print(); StreamPartitioner<?> broadcastPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), broadcastSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(broadcastPartitioner instanceof BroadcastPartitioner); DataStream<Long> shuffle = src.shuffle(); DataStreamSink<Long> shuffleSink = shuffle.print(); StreamPartitioner<?> shufflePartitioner = env.getStreamGraph().getStreamEdges(src.getId(), shuffleSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(shufflePartitioner instanceof ShufflePartitioner); DataStream<Long> forward = src.forward(); DataStreamSink<Long> forwardSink = forward.print(); StreamPartitioner<?> forwardPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), forwardSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(forwardPartitioner instanceof ForwardPartitioner); DataStream<Long> rebalance = src.rebalance(); DataStreamSink<Long> rebalanceSink = rebalance.print(); StreamPartitioner<?> rebalancePartitioner = env.getStreamGraph().getStreamEdges(src.getId(), rebalanceSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(rebalancePartitioner instanceof RebalancePartitioner); DataStream<Long> global = src.global(); DataStreamSink<Long> globalSink = global.print(); StreamPartitioner<?> globalPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), globalSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(globalPartitioner instanceof GlobalPartitioner); }
Example #23
Source File: DataStreamTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testChannelSelectors() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStreamSource<Long> src = env.generateSequence(0, 0); DataStream<Long> broadcast = src.broadcast(); DataStreamSink<Long> broadcastSink = broadcast.print(); StreamPartitioner<?> broadcastPartitioner = getStreamGraph(env).getStreamEdges(src.getId(), broadcastSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(broadcastPartitioner instanceof BroadcastPartitioner); DataStream<Long> shuffle = src.shuffle(); DataStreamSink<Long> shuffleSink = shuffle.print(); StreamPartitioner<?> shufflePartitioner = getStreamGraph(env).getStreamEdges(src.getId(), shuffleSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(shufflePartitioner instanceof ShufflePartitioner); DataStream<Long> forward = src.forward(); DataStreamSink<Long> forwardSink = forward.print(); StreamPartitioner<?> forwardPartitioner = getStreamGraph(env).getStreamEdges(src.getId(), forwardSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(forwardPartitioner instanceof ForwardPartitioner); DataStream<Long> rebalance = src.rebalance(); DataStreamSink<Long> rebalanceSink = rebalance.print(); StreamPartitioner<?> rebalancePartitioner = getStreamGraph(env).getStreamEdges(src.getId(), rebalanceSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(rebalancePartitioner instanceof RebalancePartitioner); DataStream<Long> global = src.global(); DataStreamSink<Long> globalSink = global.print(); StreamPartitioner<?> globalPartitioner = getStreamGraph(env).getStreamEdges(src.getId(), globalSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(globalPartitioner instanceof GlobalPartitioner); }
Example #24
Source File: StreamingJobGraphGenerator.java From flink with Apache License 2.0 | 4 votes |
private void connect(Integer headOfChain, StreamEdge edge) { physicalEdgesInOrder.add(edge); Integer downStreamvertexID = edge.getTargetId(); JobVertex headVertex = jobVertices.get(headOfChain); JobVertex downStreamVertex = jobVertices.get(downStreamvertexID); StreamConfig downStreamConfig = new StreamConfig(downStreamVertex.getConfiguration()); downStreamConfig.setNumberOfInputs(downStreamConfig.getNumberOfInputs() + 1); StreamPartitioner<?> partitioner = edge.getPartitioner(); ResultPartitionType resultPartitionType; switch (edge.getShuffleMode()) { case PIPELINED: resultPartitionType = ResultPartitionType.PIPELINED_BOUNDED; break; case BATCH: resultPartitionType = ResultPartitionType.BLOCKING; break; case UNDEFINED: resultPartitionType = streamGraph.isBlockingConnectionsBetweenChains() ? ResultPartitionType.BLOCKING : ResultPartitionType.PIPELINED_BOUNDED; break; default: throw new UnsupportedOperationException("Data exchange mode " + edge.getShuffleMode() + " is not supported yet."); } JobEdge jobEdge; if (partitioner instanceof ForwardPartitioner || partitioner instanceof RescalePartitioner) { jobEdge = downStreamVertex.connectNewDataSetAsInput( headVertex, DistributionPattern.POINTWISE, resultPartitionType); } else { jobEdge = downStreamVertex.connectNewDataSetAsInput( headVertex, DistributionPattern.ALL_TO_ALL, resultPartitionType); } // set strategy name so that web interface can show it. jobEdge.setShipStrategyName(partitioner.toString()); if (LOG.isDebugEnabled()) { LOG.debug("CONNECTED: {} - {} -> {}", partitioner.getClass().getSimpleName(), headOfChain, downStreamvertexID); } }
Example #25
Source File: DataStreamTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testChannelSelectors() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStreamSource<Long> src = env.generateSequence(0, 0); DataStream<Long> broadcast = src.broadcast(); DataStreamSink<Long> broadcastSink = broadcast.print(); StreamPartitioner<?> broadcastPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), broadcastSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(broadcastPartitioner instanceof BroadcastPartitioner); DataStream<Long> shuffle = src.shuffle(); DataStreamSink<Long> shuffleSink = shuffle.print(); StreamPartitioner<?> shufflePartitioner = env.getStreamGraph().getStreamEdges(src.getId(), shuffleSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(shufflePartitioner instanceof ShufflePartitioner); DataStream<Long> forward = src.forward(); DataStreamSink<Long> forwardSink = forward.print(); StreamPartitioner<?> forwardPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), forwardSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(forwardPartitioner instanceof ForwardPartitioner); DataStream<Long> rebalance = src.rebalance(); DataStreamSink<Long> rebalanceSink = rebalance.print(); StreamPartitioner<?> rebalancePartitioner = env.getStreamGraph().getStreamEdges(src.getId(), rebalanceSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(rebalancePartitioner instanceof RebalancePartitioner); DataStream<Long> global = src.global(); DataStreamSink<Long> globalSink = global.print(); StreamPartitioner<?> globalPartitioner = env.getStreamGraph().getStreamEdges(src.getId(), globalSink.getTransformation().getId()).get(0).getPartitioner(); assertTrue(globalPartitioner instanceof GlobalPartitioner); }
Example #26
Source File: DataStream.java From flink with Apache License 2.0 | 2 votes |
/** * Sets the partitioning of the {@link DataStream} so that the output elements * are forwarded to the local subtask of the next operation. * * @return The DataStream with forward partitioning set. */ public DataStream<T> forward() { return setConnectionType(new ForwardPartitioner<T>()); }
Example #27
Source File: DataStream.java From flink with Apache License 2.0 | 2 votes |
/** * Sets the partitioning of the {@link DataStream} so that the output elements * are forwarded to the local subtask of the next operation. * * @return The DataStream with forward partitioning set. */ public DataStream<T> forward() { return setConnectionType(new ForwardPartitioner<T>()); }
Example #28
Source File: DataStream.java From Flink-CEPplus with Apache License 2.0 | 2 votes |
/** * Sets the partitioning of the {@link DataStream} so that the output elements * are forwarded to the local subtask of the next operation. * * @return The DataStream with forward partitioning set. */ public DataStream<T> forward() { return setConnectionType(new ForwardPartitioner<T>()); }