Class Stream<T>
- Type Parameters:
T
- the type of the value
- Direct Known Subclasses:
PairStream
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription<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.Returns an array of streams by splitting the given stream into multiple branches based on the given predicates.count()
Counts the number of values in this stream.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
Performs an action for each element of this stream.<R> Stream<R>
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 aPairFunction
on each value of this stream.partitionBy
(Fields fields, int parallelism) 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.Performs a reduction on the elements of this stream, by repeatedly applying the reducer.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
Sends the elements of this stream to a bolt.void
Sends the elements of this stream to a bolt.Returns a new stream consisting of the elements that fall within the window as specified by the window parameter.
-
Field Details
-
KEY
-
VALUE
-
KEY_VALUE
-
streamBuilder
-
node
protected final org.apache.storm.streams.Node node -
stream
-
-
Method Details
-
filter
Returns a stream consisting of the elements of this stream that matches the given filter.- Parameters:
predicate
- the predicate to apply to each element to determine if it should be included- Returns:
- the new stream
-
map
Returns a stream consisting of the result of applying the given mapping function to the values of this stream.- Parameters:
function
- a mapping function to be applied to each value in this stream.- Returns:
- the new stream
-
mapToPair
Returns a stream of key-value pairs by applying aPairFunction
on each value of this stream.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
function
- the mapping function to be applied to each value in this stream- Returns:
- the new stream of key-value pairs
-
flatMap
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.- Parameters:
function
- a mapping function to be applied to each value in this stream which produces new values.- Returns:
- the new stream
-
flatMapToPair
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.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
function
- the mapping function to be applied to each value in this stream which produces new key-value pairs.- Returns:
- the new stream of key-value pairs
- See Also:
-
window
Returns a new stream consisting of the elements that fall within the window as specified by the window parameter. TheWindow
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));
- Parameters:
window
- the window configuration- Returns:
- the new stream
- See Also:
-
forEach
Performs an action for each element of this stream.- Parameters:
action
- an action to perform on the elements
-
peek
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.- Parameters:
action
- the action to perform on the element as they are consumed from the stream- Returns:
- the new stream
-
aggregate
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.
- Type Parameters:
A
- the accumulator typeR
- the result type- Parameters:
aggregator
- the aggregator- Returns:
- the new stream
-
aggregate
public <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.
- Type Parameters:
R
- the result type- Parameters:
initialValue
- the initial value of the resultaccumulator
- the accumulatorcombiner
- the combiner- Returns:
- the new stream
-
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.
- Returns:
- the new stream
-
reduce
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.
- Parameters:
reducer
- the reducer- Returns:
- the new stream
-
repartition
Returns a new stream with the given value of parallelism. Further operations on this stream would execute at this level of parallelism.- Parameters:
parallelism
- the parallelism value- Returns:
- the new stream
-
branch
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.
- Parameters:
predicates
- the predicates- Returns:
- an array of result streams (branches) corresponding to the given predicates
-
print
public void print()Print the values in this stream. -
to
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. aRedisStoreBolt
. The bolt would have a parallelism of 1.Note: This would provide guarantees only based on what the bolt provides.
- Parameters:
bolt
- the bolt
-
to
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. aRedisStoreBolt
.Note: This would provide guarantees only based on what the bolt provides.
- Parameters:
bolt
- the boltparallelism
- the parallelism of the bolt
-
to
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. aRedisStoreBolt
. The bolt would have a parallelism of 1.Note: This would provide guarantees only based on what the bolt provides.
- Parameters:
bolt
- the bolt
-
to
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. aRedisStoreBolt
.Note: This would provide guarantees only based on what the bolt provides.
- Parameters:
bolt
- the boltparallelism
- the parallelism of the bolt
-
stateQuery
Queries the given stream state with the values in this stream as the keys.- Type Parameters:
V
- the value type- Parameters:
streamState
- the stream state- Returns:
- the result stream
-
partitionBy
-