Class NumberSequenceSource
- java.lang.Object
-
- org.apache.flink.api.connector.source.lib.NumberSequenceSource
-
- All Implemented Interfaces:
Serializable
,Source<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
,SourceReaderFactory<Long,NumberSequenceSource.NumberSequenceSplit>
,ResultTypeQueryable<Long>
@Public public class NumberSequenceSource extends Object implements Source<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>, ResultTypeQueryable<Long>
A data source that produces a sequence of numbers (longs). This source is useful for testing and for cases that just need a stream of N events of any kind.The source splits the sequence into as many parallel sub-sequences as there are parallel source readers. Each sub-sequence will be produced in order. Consequently, if the parallelism is limited to one, this will produce one sequence in order.
This source is always bounded. For very long sequences (for example over the entire domain of long integer values), user may want to consider executing the application in a streaming manner, because, despite the fact that the produced stream is bounded, the end bound is pretty far away.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NumberSequenceSource.NumberSequenceSplit
A split of the source, representing a number sub-sequence.
-
Constructor Summary
Constructors Constructor Description NumberSequenceSource(long from, long to)
Creates a newNumberSequenceSource
that produces parallel sequences covering the rangefrom
toto
(both boundaries are inclusive).
-
Method Summary
-
-
-
Method Detail
-
getFrom
public long getFrom()
-
getTo
public long getTo()
-
getProducedType
public TypeInformation<Long> getProducedType()
Description copied from interface:ResultTypeQueryable
Gets the data type (as aTypeInformation
) produced by this function or input format.- Specified by:
getProducedType
in interfaceResultTypeQueryable<Long>
- Returns:
- The data type produced by this function or input format.
-
getBoundedness
public Boundedness getBoundedness()
Description copied from interface:Source
Get the boundedness of this source.- Specified by:
getBoundedness
in interfaceSource<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
- Returns:
- the boundedness of this source.
-
createReader
public SourceReader<Long,NumberSequenceSource.NumberSequenceSplit> createReader(SourceReaderContext readerContext)
Description copied from interface:SourceReaderFactory
Creates a new reader to read data from the splits it gets assigned. The reader starts fresh and does not have any state to resume.- Specified by:
createReader
in interfaceSourceReaderFactory<Long,NumberSequenceSource.NumberSequenceSplit>
- Parameters:
readerContext
- Thecontext
for the source reader.- Returns:
- A new SourceReader.
-
createEnumerator
public SplitEnumerator<NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>> createEnumerator(SplitEnumeratorContext<NumberSequenceSource.NumberSequenceSplit> enumContext)
Description copied from interface:Source
Creates a new SplitEnumerator for this source, starting a new input.- Specified by:
createEnumerator
in interfaceSource<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
- Parameters:
enumContext
- Thecontext
for the split enumerator.- Returns:
- A new SplitEnumerator.
-
restoreEnumerator
public SplitEnumerator<NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>> restoreEnumerator(SplitEnumeratorContext<NumberSequenceSource.NumberSequenceSplit> enumContext, Collection<NumberSequenceSource.NumberSequenceSplit> checkpoint)
Description copied from interface:Source
Restores an enumerator from a checkpoint.- Specified by:
restoreEnumerator
in interfaceSource<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
- Parameters:
enumContext
- Thecontext
for the restored split enumerator.checkpoint
- The checkpoint to restore the SplitEnumerator from.- Returns:
- A SplitEnumerator restored from the given checkpoint.
-
getSplitSerializer
public SimpleVersionedSerializer<NumberSequenceSource.NumberSequenceSplit> getSplitSerializer()
Description copied from interface:Source
Creates a serializer for the source splits. Splits are serialized when sending them from enumerator to reader, and when checkpointing the reader's current state.- Specified by:
getSplitSerializer
in interfaceSource<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
- Returns:
- The serializer for the split type.
-
getEnumeratorCheckpointSerializer
public SimpleVersionedSerializer<Collection<NumberSequenceSource.NumberSequenceSplit>> getEnumeratorCheckpointSerializer()
Description copied from interface:Source
Creates the serializer for theSplitEnumerator
checkpoint. The serializer is used for the result of theSplitEnumerator.snapshotState(long)
method.- Specified by:
getEnumeratorCheckpointSerializer
in interfaceSource<Long,NumberSequenceSource.NumberSequenceSplit,Collection<NumberSequenceSource.NumberSequenceSplit>>
- Returns:
- The serializer for the SplitEnumerator checkpoint.
-
splitNumberRange
protected List<NumberSequenceSource.NumberSequenceSplit> splitNumberRange(long from, long to, int numSplits)
-
-