public class CountingSource
extends java.lang.Object
GenerateSequence
instead.
A source that produces longs. When used as a BoundedSource
, CountingSource
starts at 0
and counts up to a specified maximum. When used as an UnboundedSource
, it counts up to Long.MAX_VALUE
and then never produces more output. (In
practice, this limit should never be reached.)
The bounded CountingSource
is implemented based on OffsetBasedSource
and
OffsetBasedSource.OffsetBasedReader
, so it performs efficient initial splitting and it
supports dynamic work rebalancing.
To produce a bounded source, use createSourceForSubrange(long, long)
. To produce an
unbounded source, use createUnboundedFrom(long)
.
Modifier and Type | Class and Description |
---|---|
static class |
CountingSource.CounterMark
The checkpoint for an unbounded
CountingSource is simply the last value produced. |
static class |
CountingSource.CounterMarkCoder
A custom coder for
CounterMark . |
Modifier and Type | Method and Description |
---|---|
static UnboundedSource<java.lang.Long,CountingSource.CounterMark> |
unbounded()
Deprecated.
use
GenerateSequence instead |
static UnboundedSource<java.lang.Long,CountingSource.CounterMark> |
unboundedWithTimestampFn(SerializableFunction<java.lang.Long,Instant> timestampFn)
Deprecated.
use
GenerateSequence and call GenerateSequence.withTimestampFn(SerializableFunction) instead |
static BoundedSource<java.lang.Long> |
upTo(long numElements)
Deprecated.
use
GenerateSequence instead |
@Deprecated public static BoundedSource<java.lang.Long> upTo(long numElements)
GenerateSequence
insteadBoundedSource
that will produce the specified number of elements, from 0
to numElements - 1
.@Deprecated public static UnboundedSource<java.lang.Long,CountingSource.CounterMark> unbounded()
GenerateSequence
insteadUnboundedSource
that will produce numbers starting from 0
up to
Long.MAX_VALUE
.
After Long.MAX_VALUE
, the source never produces more output. (In practice, this
limit should never be reached.)
Elements in the resulting PCollection<Long>
will have timestamps
corresponding to processing time at element generation, provided by Instant.now()
.
@Deprecated public static UnboundedSource<java.lang.Long,CountingSource.CounterMark> unboundedWithTimestampFn(SerializableFunction<java.lang.Long,Instant> timestampFn)
GenerateSequence
and call GenerateSequence.withTimestampFn(SerializableFunction)
insteadUnboundedSource
that will produce numbers starting from 0
up to
Long.MAX_VALUE
, with element timestamps supplied by the specified function.
After Long.MAX_VALUE
, the source never produces more output. (In practice, this
limit should never be reached.)
Note that the timestamps produced by timestampFn
may not decrease.