T
- the type of the value@InterfaceStability.Unstable public class Stream<T> extends Object
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)
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)
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)
PairFunction
on each value of this stream.K
- the key typeV
- the value typefunction
- the mapping function to be applied to each value in this streampublic <R> Stream<R> flatMap(FlatMapFunction<? super T,? extends R> function)
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)
K
- the key typeV
- the value typefunction
- the mapping function to be applied to each value in this stream which produces new key-value pairs.flatMap(FlatMapFunction)
,
mapToPair(PairFunction)
public Stream<T> window(Window<?,?> window)
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)
action
- an action to perform on the elementspublic Stream<T> peek(Consumer<? super T> action)
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)
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.
A
- the accumulator typeR
- the result typeaggregator
- the aggregatorpublic <R> Stream<R> aggregate(R initialValue, BiFunction<? super R,? super T,? extends R> accumulator, BiFunction<? super R,? super R,? extends R> combiner)
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.
R
- the result typeinitialValue
- the initial value of the resultaccumulator
- the accumulatorcombiner
- the combinerpublic Stream<Long> count()
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)
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)
parallelism
- the parallelism valuepublic Stream<T>[] branch(Predicate<? super T>... predicates)
Note: If none of the predicates match a value, that value is dropped.
predicates
- the predicatespublic void print()
public void to(IRichBolt bolt)
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)
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)
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)
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)
V
- the value typestreamState
- the stream stateCopyright © 2023 The Apache Software Foundation. All rights reserved.