@InterfaceStability.Unstable public class Stream<T> extends Object
Represents a stream of values.
Modifier and Type | Field and Description |
---|---|
protected static Fields |
KEY |
protected static Fields |
KEY_VALUE |
protected org.apache.storm.streams.Node |
node |
protected String |
stream |
protected StreamBuilder |
streamBuilder |
protected static Fields |
VALUE |
Modifier and Type | Method and Description |
---|---|
<A,R> Stream<R> |
aggregate(CombinerAggregator<? super T,A,? extends R> aggregator)
Aggregates the values in this stream using the aggregator.
|
<R> Stream<R> |
aggregate(R initialValue,
BiFunction<? super R,? super T,? extends R> accumulator,
BiFunction<? super R,? super R,? extends R> combiner)
Aggregates the values in this stream using the given initial value, accumulator and combiner.
|
Stream<T>[] |
branch(Predicate<? super T>... predicates)
Returns an array of streams by splitting the given stream into multiple branches based on the given predicates.
|
Stream<Long> |
count()
Counts the number of values in this stream.
|
Stream<T> |
filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that matches the given filter.
|
<R> Stream<R> |
flatMap(FlatMapFunction<? super T,? extends R> function)
Returns a stream consisting of the results of replacing each value of this stream with the contents produced by applying the provided mapping function to each value.
|
<K,V> PairStream<K,V> |
flatMapToPair(PairFlatMapFunction<? super T,? extends K,? extends V> function)
Returns a stream consisting of the results of replacing each value of this stream with the key-value pairs produced by applying the provided mapping function to each value.
|
void |
forEach(Consumer<? super T> action)
Performs an action for each element of this stream.
|
<R> Stream<R> |
map(Function<? super T,? extends R> function)
Returns a stream consisting of the result of applying the given mapping function to the values of this stream.
|
<K,V> PairStream<K,V> |
mapToPair(PairFunction<? super T,? extends K,? extends V> function)
Returns a stream of key-value pairs by applying a
PairFunction on each value of this stream. |
protected Stream<T> |
partitionBy(Fields fields,
int parallelism) |
Stream<T> |
peek(Consumer<? super T> action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as they are consumed from the resulting stream.
|
void |
print()
Print the values in this stream.
|
Stream<T> |
reduce(Reducer<T> reducer)
Performs a reduction on the elements of this stream, by repeatedly applying the reducer.
|
Stream<T> |
repartition(int parallelism)
Returns a new stream with the given value of parallelism.
|
<V> PairStream<T,V> |
stateQuery(StreamState<T,V> streamState)
Queries the given stream state with the values in this stream as the keys.
|
void |
to(IBasicBolt bolt)
Sends the elements of this stream to a bolt.
|
void |
to(IBasicBolt bolt,
int parallelism)
Sends the elements of this stream to a bolt.
|
void |
to(IRichBolt bolt)
Sends the elements of this stream to a bolt.
|
void |
to(IRichBolt bolt,
int parallelism)
Sends the elements of this stream to a bolt.
|
Stream<T> |
window(Window<?,?> window)
Returns a new stream consisting of the elements that fall within the window as specified by the window parameter.
|
protected static final Fields KEY
protected static final Fields VALUE
protected static final Fields KEY_VALUE
protected final StreamBuilder streamBuilder
protected final org.apache.storm.streams.Node node
protected final String stream
public Stream<T> filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that matches the given filter.
predicate
- the predicate to apply to each element to determine if it should be includedpublic <R> Stream<R> map(Function<? super T,? extends R> function)
Returns a stream consisting of the result of applying the given mapping function to the values of this stream.
function
- a mapping function to be applied to each value in this stream.public <K,V> PairStream<K,V> mapToPair(PairFunction<? super T,? extends K,? extends V> function)
Returns a stream of key-value pairs by applying a PairFunction
on each value of this stream.
function
- the mapping function to be applied to each value in this streamK
- the key typeV
- the value typepublic <R> Stream<R> flatMap(FlatMapFunction<? super T,? extends R> function)
Returns a stream consisting of the results of replacing each value of this stream with the contents produced by applying the provided mapping function to each value. This has the effect of applying a one-to-many transformation to the values of the stream, and then flattening the resulting elements into a new stream.
function
- a mapping function to be applied to each value in this stream which produces new values.public <K,V> PairStream<K,V> flatMapToPair(PairFlatMapFunction<? super T,? extends K,? extends V> function)
Returns a stream consisting of the results of replacing each value of this stream with the key-value pairs produced by applying the provided mapping function to each value.
function
- the mapping function to be applied to each value in this stream which produces new key-value pairs.K
- the key typeV
- the value typeflatMap(FlatMapFunction)
,
mapToPair(PairFunction)
public Stream<T> window(Window<?,?> window)
Returns a new stream consisting of the elements that fall within the window as specified by the window parameter. The Window
specification could be used to specify sliding or tumbling windows based on time duration or event count. For example,
// time duration based sliding window stream.window(SlidingWindows.of(Duration.minutes(10), Duration.minutes(1));// count based sliding window stream.window(SlidingWindows.of(Count.(10), Count.of(2)));
// time duration based tumbling window stream.window(TumblingWindows.of(Duration.seconds(10));
window
- the window configurationSlidingWindows
,
TumblingWindows
public void forEach(Consumer<? super T> action)
Performs an action for each element of this stream.
action
- an action to perform on the elementspublic Stream<T> peek(Consumer<? super T> action)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as they are consumed from the resulting stream.
action
- the action to perform on the element as they are consumed from the streampublic <A,R> Stream<R> aggregate(CombinerAggregator<? super T,A,? extends R> aggregator)
Aggregates the values in this stream using the aggregator. This does a global aggregation of values across all partitions.
If the stream is windowed, the aggregate result is emitted after each window activation and represents the aggregate of elements that fall within that window. If the stream is not windowed, the aggregate result is emitted as each new element in the stream is processed.
aggregator
- the aggregatorA
- the accumulator typeR
- the result typepublic <R> Stream<R> aggregate(R initialValue, BiFunction<? super R,? super T,? extends R> accumulator, BiFunction<? super R,? super R,? extends R> combiner)
Aggregates the values in this stream using the given initial value, accumulator and combiner. This does a global aggregation of values across all partitions.
If the stream is windowed, the aggregate result is emitted after each window activation and represents the aggregate of elements that fall within that window. If the stream is not windowed, the aggregate result is emitted as each new element in the stream is processed.
initialValue
- the initial value of the resultaccumulator
- the accumulatorcombiner
- the combinerR
- the result typepublic Stream<Long> count()
Counts the number of values in this stream. This does a global count of values across all partitions.
If the stream is windowed, the counts are emitted after each window activation and represents the count of elements that fall within that window. If the stream is not windowed, the count is emitted as each new element in the stream is processed.
public Stream<T> reduce(Reducer<T> reducer)
Performs a reduction on the elements of this stream, by repeatedly applying the reducer. This does a global reduction of values across all partitions.
If the stream is windowed, the result is emitted after each window activation and represents the reduction of elements that fall within that window. If the stream is not windowed, the result is emitted as each new element in the stream is processed.
reducer
- the reducerpublic Stream<T> repartition(int parallelism)
Returns a new stream with the given value of parallelism. Further operations on this stream would execute at this level of parallelism.
parallelism
- the parallelism valuepublic Stream<T>[] branch(Predicate<? super T>... predicates)
Returns an array of streams by splitting the given stream into multiple branches based on the given predicates. The predicates are applied in the given order to the values of this stream and the result is forwarded to the corresponding (index based) result stream based on the (index of) predicate that matches.
Note: If none of the predicates match a value, that value is dropped.
predicates
- the predicatespublic void print()
Print the values in this stream.
public void to(IRichBolt bolt)
Sends the elements of this stream to a bolt. This could be used to plug in existing bolts as sinks in the stream, for e.g. a RedisStoreBolt
. The bolt would have a parallelism of 1.
Note: This would provide guarantees only based on what the bolt provides.
bolt
- the boltpublic void to(IRichBolt bolt, int parallelism)
Sends the elements of this stream to a bolt. This could be used to plug in existing bolts as sinks in the stream, for e.g. a RedisStoreBolt
.
Note: This would provide guarantees only based on what the bolt provides.
bolt
- the boltparallelism
- the parallelism of the boltpublic void to(IBasicBolt bolt)
Sends the elements of this stream to a bolt. This could be used to plug in existing bolts as sinks in the stream, for e.g. a RedisStoreBolt
. The bolt would have a parallelism of 1.
Note: This would provide guarantees only based on what the bolt provides.
bolt
- the boltpublic void to(IBasicBolt bolt, int parallelism)
Sends the elements of this stream to a bolt. This could be used to plug in existing bolts as sinks in the stream, for e.g. a RedisStoreBolt
.
Note: This would provide guarantees only based on what the bolt provides.
bolt
- the boltparallelism
- the parallelism of the boltpublic <V> PairStream<T,V> stateQuery(StreamState<T,V> streamState)
Queries the given stream state with the values in this stream as the keys.
streamState
- the stream stateV
- the value typeCopyright © 2020 The Apache Software Foundation. All rights reserved.