Class GenerateSequence
- All Implemented Interfaces:
Serializable
,HasDisplayData
PTransform
that produces longs starting from the given value, and either up to the
given limit or until Long.MAX_VALUE
/ until the given time elapses.
The bounded GenerateSequence
is implemented based on OffsetBasedSource
and
OffsetBasedSource.OffsetBasedReader
, so it performs efficient initial splitting and it
supports dynamic work rebalancing.
To produce a bounded PCollection<Long>
:
Pipeline p = ...
PCollection<Long> bounded = p.apply(GenerateSequence.from(0).to(1000));
To produce an unbounded PCollection<Long>
, simply do not specify to(long)
,
calling withTimestampFn(SerializableFunction)
to provide values with timestamps other
than Instant.now()
.
Pipeline p = ...
// To use processing time as the element timestamp.
PCollection<Long> unbounded = p.apply(GenerateSequence.from(0));
// Or, to use a provided function to set the element timestamp.
PCollection<Long> unboundedWithTimestamps =
p.apply(GenerateSequence.from(0).withTimestampFn(someFn));
In all cases, the sequence of numbers is generated in parallel, so there is no inherent
ordering between the generated values - it is only guaranteed that all values in the given range
will be present in the resulting PCollection
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exposes GenerateSequence as an external transform for cross-language usage. -
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionOverride this method to specify how thisPTransform
should be expanded on the givenInputT
.static GenerateSequence
from
(long from) Specifies the minimum number to generate (inclusive).void
populateDisplayData
(DisplayData.Builder builder) Register display data for the given transform or component.to
(long to) Specifies the maximum number to generate (exclusive).withMaxReadTime
(Duration maxReadTime) Specifies to stop generating elements after the given time.Specifies to generate at most a given number of elements per a given period.withTimestampFn
(SerializableFunction<Long, Instant> timestampFn) Specifies the function to use to assign timestamps to the elements.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, setDisplayData, setResourceHints, toString, validate, validate
-
Constructor Details
-
GenerateSequence
public GenerateSequence()
-
-
Method Details
-
from
Specifies the minimum number to generate (inclusive). -
to
Specifies the maximum number to generate (exclusive). -
withTimestampFn
Specifies the function to use to assign timestamps to the elements. -
withRate
Specifies to generate at most a given number of elements per a given period. -
withMaxReadTime
Specifies to stop generating elements after the given time. -
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
- Specified by:
expand
in classPTransform<PBegin,
PCollection<Long>>
-
populateDisplayData
Description copied from class:PTransform
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.populateDisplayData(builder)
to use the namespace of the subcomponent.By default, does not register any display data. Implementors may override this method to provide their own display data.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Overrides:
populateDisplayData
in classPTransform<PBegin,
PCollection<Long>> - Parameters:
builder
- The builder to populate with display data.- See Also:
-