Search in sources :

Example 6 with NumberSequenceSource

use of org.apache.flink.api.connector.source.lib.NumberSequenceSource in project flink by apache.

the class StreamingJobGraphGeneratorTest method createGraphWithMultipleInputs.

public JobGraph createGraphWithMultipleInputs(boolean chain, String... inputNames) {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    MultipleInputTransformation<Long> transform = new MultipleInputTransformation<>("mit", new UnusedOperatorFactory(), Types.LONG, env.getParallelism());
    Arrays.stream(inputNames).map(name -> env.fromSource(new NumberSequenceSource(1, 2), WatermarkStrategy.noWatermarks(), name).getTransformation()).forEach(transform::addInput);
    transform.setChainingStrategy(chain ? ChainingStrategy.HEAD_WITH_SOURCES : ChainingStrategy.NEVER);
    env.addOperator(transform);
    return StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph());
}
Also used : Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TypeSerializerInputFormat(org.apache.flink.api.java.io.TypeSerializerInputFormat) YieldingOperatorFactory(org.apache.flink.streaming.api.operators.YieldingOperatorFactory) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) UserCodeWrapper(org.apache.flink.api.common.operators.util.UserCodeWrapper) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) Map(java.util.Map) CoLocationGroup(org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroup) ForwardPartitioner(org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) Set(java.util.Set) FlatMapFunction(org.apache.flink.api.common.functions.FlatMapFunction) FilterFunction(org.apache.flink.api.common.functions.FilterFunction) Assert.assertFalse(org.junit.Assert.assertFalse) StreamingJobGraphGenerator.areOperatorsChainable(org.apache.flink.streaming.api.graph.StreamingJobGraphGenerator.areOperatorsChainable) Boundedness(org.apache.flink.api.connector.source.Boundedness) OneInputStreamOperatorFactory(org.apache.flink.streaming.api.operators.OneInputStreamOperatorFactory) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ArrayList(java.util.ArrayList) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) Collector(org.apache.flink.util.Collector) Iterables(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Types(org.apache.flink.api.common.typeinfo.Types) DataStreamSink(org.apache.flink.streaming.api.datastream.DataStreamSink) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) SingleOutputStreamOperator(org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) Assert.assertNull(org.junit.Assert.assertNull) Matcher(org.hamcrest.Matcher) Transformation(org.apache.flink.api.dag.Transformation) Assert(org.junit.Assert) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) Assert.assertEquals(org.junit.Assert.assertEquals) CoreMatchers.is(org.hamcrest.CoreMatchers.is) PipelineOptions(org.apache.flink.configuration.PipelineOptions) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CheckpointingMode(org.apache.flink.streaming.api.CheckpointingMode) MapFunction(org.apache.flink.api.common.functions.MapFunction) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) TestLogger(org.apache.flink.util.TestLogger) InputFormat(org.apache.flink.api.common.io.InputFormat) Assert.fail(org.junit.Assert.fail) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) Method(java.lang.reflect.Method) OutputFormat(org.apache.flink.api.common.io.OutputFormat) JobCheckpointingSettings(org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) WatermarkStrategy(org.apache.flink.api.common.eventtime.WatermarkStrategy) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) SimpleOperatorFactory(org.apache.flink.streaming.api.operators.SimpleOperatorFactory) List(java.util.List) MultipleInputStreamTask(org.apache.flink.streaming.runtime.tasks.MultipleInputStreamTask) SerializedValue(org.apache.flink.util.SerializedValue) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) IterativeStream(org.apache.flink.streaming.api.datastream.IterativeStream) StreamOperatorFactory(org.apache.flink.streaming.api.operators.StreamOperatorFactory) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) HashMap(java.util.HashMap) DataStreamSource(org.apache.flink.streaming.api.datastream.DataStreamSource) JobType(org.apache.flink.runtime.jobgraph.JobType) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory) MockSource(org.apache.flink.api.connector.source.mocks.MockSource) SourceOperatorStreamTask(org.apache.flink.streaming.runtime.tasks.SourceOperatorStreamTask) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) ReduceFunction(org.apache.flink.api.common.functions.ReduceFunction) RebalancePartitioner(org.apache.flink.streaming.runtime.partitioner.RebalancePartitioner) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) Assert.assertNotNull(org.junit.Assert.assertNotNull) Configuration(org.apache.flink.configuration.Configuration) CoordinatedOperatorFactory(org.apache.flink.streaming.api.operators.CoordinatedOperatorFactory) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) InputFormatSourceFunction(org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction) DataStream(org.apache.flink.streaming.api.datastream.DataStream) RescalePartitioner(org.apache.flink.streaming.runtime.partitioner.RescalePartitioner) FeatureMatcher(org.hamcrest.FeatureMatcher) StreamExchangeMode(org.apache.flink.streaming.api.transformations.StreamExchangeMode) TestAnyModeReadingStreamOperator(org.apache.flink.streaming.util.TestAnyModeReadingStreamOperator) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer) Comparator(java.util.Comparator) RuntimeExecutionMode(org.apache.flink.api.common.RuntimeExecutionMode) Collections(java.util.Collections) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation)

Example 7 with NumberSequenceSource

use of org.apache.flink.api.connector.source.lib.NumberSequenceSource in project flink by apache.

the class AlignedWatermarksITCase method getJobGraph.

private JobGraph getJobGraph() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().setAutoWatermarkInterval(0L);
    env.setParallelism(1);
    DataStream<Long> slowSource = env.fromSource(new NumberSequenceSource(0, Long.MAX_VALUE), WatermarkStrategy.forGenerator(ctx -> new PunctuatedGenerator()).withWatermarkAlignment("group-1", Duration.ofMillis(MAX_DRIFT), UPDATE_INTERVAL).withTimestampAssigner((r, t) -> r), SLOW_SOURCE_NAME).map(new RichMapFunction<Long, Long>() {

        @Override
        public Long map(Long value) throws Exception {
            Thread.sleep(10);
            return value;
        }
    });
    DataStream<Long> fastSource = env.fromSource(new NumberSequenceSource(0, Long.MAX_VALUE), WatermarkStrategy.forGenerator(ctx -> new PunctuatedGenerator()).withWatermarkAlignment("group-1", Duration.ofMillis(MAX_DRIFT), UPDATE_INTERVAL).withTimestampAssigner((r, t) -> r), FAST_SOURCE_NAME).map(new RichMapFunction<Long, Long>() {

        @Override
        public Long map(Long value) throws Exception {
            Thread.sleep(1);
            return value;
        }
    });
    slowSource.union(fastSource).addSink(new DiscardingSink<>());
    return env.getStreamGraph().getJobGraph();
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource)

Example 8 with NumberSequenceSource

use of org.apache.flink.api.connector.source.lib.NumberSequenceSource in project flink by apache.

the class SourceNAryInputChainingITCase method createProgramWithUnionInput.

/**
 * Creates a DataStream program as shown below.
 *
 * <pre>
 *                                   +--------------+
 *             (src 1) --> (map) --> |              |
 *                                   |              |
 *            (src 2) --+            |    N-Ary     |
 *                      +-- UNION -> |   Operator   |
 *   (src 3) -> (map) --+            |              |
 *                                   |              |
 *                       (src 4) --> |              |
 *                                   +--------------+
 * </pre>
 */
private DataStream<Long> createProgramWithUnionInput() {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(PARALLELISM);
    env.getConfig().enableObjectReuse();
    final DataStream<Long> source1 = env.fromSource(new NumberSequenceSource(1L, 10L), WatermarkStrategy.noWatermarks(), "source-1");
    final DataStream<Long> source2 = env.fromSource(new NumberSequenceSource(11L, 20L), WatermarkStrategy.noWatermarks(), "source-2");
    final DataStream<Long> source3 = env.fromSource(new NumberSequenceSource(21L, 30L), WatermarkStrategy.noWatermarks(), "source-3");
    final DataStream<Long> source4 = env.fromSource(new NumberSequenceSource(31L, 40L), WatermarkStrategy.noWatermarks(), "source-4");
    return nAryInputStreamOperation(source1.map((v) -> v), source2.union(source3), source4);
}
Also used : MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource) MultipleConnectedStreams(org.apache.flink.streaming.api.datastream.MultipleConnectedStreams) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) AbstractStreamOperatorV2(org.apache.flink.streaming.api.operators.AbstractStreamOperatorV2) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) AbstractInput(org.apache.flink.streaming.api.operators.AbstractInput) ArrayList(java.util.ArrayList) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Types(org.apache.flink.api.common.typeinfo.Types) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) DataStreamUtils(org.apache.flink.streaming.api.datastream.DataStreamUtils) WatermarkStrategy(org.apache.flink.api.common.eventtime.WatermarkStrategy) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) Test(org.junit.Test) StreamingJobGraphGenerator(org.apache.flink.streaming.api.graph.StreamingJobGraphGenerator) DataStream(org.apache.flink.streaming.api.datastream.DataStream) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) MultipleInputStreamOperator(org.apache.flink.streaming.api.operators.MultipleInputStreamOperator) List(java.util.List) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Input(org.apache.flink.streaming.api.operators.Input) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource)

Example 9 with NumberSequenceSource

use of org.apache.flink.api.connector.source.lib.NumberSequenceSource in project flink by apache.

the class SourceNAryInputChainingITCase method createProgramWithSourcesOnly.

/**
 * Creates a DataStream program as shown below.
 *
 * <pre>
 *               +--------------+
 *   (src 1) --> |              |
 *               |     N-Ary    |
 *   (src 2) --> |              |
 *               |   Operator   |
 *   (src 3) --> |              |
 *               +--------------+
 * </pre>
 */
private DataStream<Long> createProgramWithSourcesOnly() {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(PARALLELISM);
    env.getConfig().enableObjectReuse();
    final DataStream<Long> source1 = env.fromSource(new NumberSequenceSource(1L, 10L), WatermarkStrategy.noWatermarks(), "source-1");
    final DataStream<Long> source2 = env.fromSource(new NumberSequenceSource(11L, 20L), WatermarkStrategy.noWatermarks(), "source-2");
    final DataStream<Long> source3 = env.fromSource(new NumberSequenceSource(21L, 30L), WatermarkStrategy.noWatermarks(), "source-3");
    return nAryInputStreamOperation(source1, source2, source3);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) NumberSequenceSource(org.apache.flink.api.connector.source.lib.NumberSequenceSource)

Aggregations

NumberSequenceSource (org.apache.flink.api.connector.source.lib.NumberSequenceSource)9 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)9 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WatermarkStrategy (org.apache.flink.api.common.eventtime.WatermarkStrategy)4 Types (org.apache.flink.api.common.typeinfo.Types)4 DataStream (org.apache.flink.streaming.api.datastream.DataStream)4 DiscardingSink (org.apache.flink.streaming.api.functions.sink.DiscardingSink)4 AbstractStreamOperatorFactory (org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory)4 ChainingStrategy (org.apache.flink.streaming.api.operators.ChainingStrategy)4 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)4 StreamOperatorParameters (org.apache.flink.streaming.api.operators.StreamOperatorParameters)4 MultipleInputTransformation (org.apache.flink.streaming.api.transformations.MultipleInputTransformation)4 TestLogger (org.apache.flink.util.TestLogger)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.fail (org.junit.Assert.fail)4 Method (java.lang.reflect.Method)2 Arrays (java.util.Arrays)2