Struct renoir::WindowedStream
source · pub struct WindowedStream<Op, O: Data, WinDescr>{ /* private fields */ }
Expand description
A WindowedStream
is a data stream partitioned by Key
, where elements of each partition
are divided in groups called windows.
Each element can be assigned to one or multiple windows.
Windows are handled independently for each partition of the stream. Each partition may be processed in parallel.
The windowing logic is implemented through 3 traits:
- A
WindowDescription
contains the parameters and logic that characterize the windowing strategy, when given aWindowAccumulator
it instantiates aWindowManager
. - A
WindowManger
is the struct responsible for creating the windows and forwarding the input elements to the correct window which will should pass it to itsWindowAccumulator
. - A
WindowAccumulator
contains the logic that should be applied to the elements of each window.
There are a set of provided window descriptions with their respective managers:
Implementations§
source§impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr>where
WindowDescr: WindowDescription<Out>,
OperatorChain: Operator<Out = (Key, Out)> + 'static,
Key: DataKey,
Out: Data,
impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr>where
WindowDescr: WindowDescription<Out>,
OperatorChain: Operator<Out = (Key, Out)> + 'static,
Key: DataKey,
Out: Data,
sourcepub fn fold<NewOut: Data, F>(
self,
init: NewOut,
fold: F
) -> KeyedStream<impl Operator<Out = (Key, NewOut)>>
pub fn fold<NewOut: Data, F>( self, init: NewOut, fold: F ) -> KeyedStream<impl Operator<Out = (Key, NewOut)>>
Folds the elements of each window into an accumulator value
fold()
takes two arguments: the initial value of the accumulator and a closure used to
accumulate the elements of each window.
The closure is called once for each element of each window with two arguments: a mutable reference to the accumulator and the element of the window. The closure should modify the accumulator, without returning anything.
§Example
let s = env.stream_iter(0..5);
let res = s
.group_by(|&n| n % 2)
.window(CountWindow::tumbling(2))
.fold(1, |acc, n| *acc *= n)
.collect_vec();
env.execute_blocking();
let mut res = res.get().unwrap();
res.sort_unstable();
assert_eq!(res, vec![(0, 0 * 2), (1, 1 * 3)]);
sourcepub fn fold_first<F>(
self,
fold: F
) -> KeyedStream<impl Operator<Out = (Key, Out)>>
pub fn fold_first<F>( self, fold: F ) -> KeyedStream<impl Operator<Out = (Key, Out)>>
Folds the elements of each window into an accumulator value, starting with the first value
TODO DOCS
source§impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr>where
WindowDescr: WindowDescription<Out>,
OperatorChain: Operator<Out = (Key, Out)> + 'static,
Key: DataKey,
Out: Data + Ord,
impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr>where
WindowDescr: WindowDescription<Out>,
OperatorChain: Operator<Out = (Key, Out)> + 'static,
Key: DataKey,
Out: Data + Ord,
sourcepub fn map<NewOut: Data, F: Fn(Vec<Out>) -> NewOut + Send + Clone + 'static>(
self,
f: F
) -> KeyedStream<impl Operator<Out = (Key, NewOut)>>
pub fn map<NewOut: Data, F: Fn(Vec<Out>) -> NewOut + Send + Clone + 'static>( self, f: F ) -> KeyedStream<impl Operator<Out = (Key, NewOut)>>
Prefer other aggregators if possible as they don’t save all elements