pub struct ParallelIteratorSource<Source>where
Source: IntoParallelSource,{ /* private fields */ }Expand description
Source that ingests items into a stream using the maximum parallelism. The items are from the iterators returned by a generating function.
Each replica (i.e. each core) will have a different iterator. The iterator are produced by a
generating function passed to the ParallelIteratorSource::new method.
Implementations§
Source§impl<S> ParallelIteratorSource<S>where
S: IntoParallelSource,
impl<S> ParallelIteratorSource<S>where
S: IntoParallelSource,
Sourcepub fn new(generator: S) -> Self
pub fn new(generator: S) -> Self
Create a new source that ingest items into the stream using the maximum parallelism available.
The function passed as argument is cloned in each core, and called to get the iterator for that replica. The first parameter passed to the function is a 0-based index of the replica, while the second is the total number of replicas.
§Example
// generate the numbers from 0 to 99 using multiple replicas
let n = 100;
let source = ParallelIteratorSource::new(move |id, instances| {
let chunk_size = (n + instances - 1) / instances;
let remaining = n - n.min(chunk_size * id);
let range = remaining.min(chunk_size);
let start = id * chunk_size;
let stop = id * chunk_size + range;
start..stop
});
let s = env.stream(source);Trait Implementations§
Source§impl<S> Clone for ParallelIteratorSource<S>where
S: IntoParallelSource,
impl<S> Clone for ParallelIteratorSource<S>where
S: IntoParallelSource,
Source§impl<Source> Debug for ParallelIteratorSource<Source>where
Source: IntoParallelSource,
impl<Source> Debug for ParallelIteratorSource<Source>where
Source: IntoParallelSource,
Source§impl<Source> Display for ParallelIteratorSource<Source>where
Source: IntoParallelSource,
impl<Source> Display for ParallelIteratorSource<Source>where
Source: IntoParallelSource,
Source§impl<S> Operator for ParallelIteratorSource<S>
impl<S> Operator for ParallelIteratorSource<S>
type Out = <<S as IntoParallelSource>::Iter as Iterator>::Item
Source§fn setup(&mut self, metadata: &mut ExecutionMetadata<'_>)
fn setup(&mut self, metadata: &mut ExecutionMetadata<'_>)
Setup the operator chain. This is called before any call to
next and it’s used to
initialize the operator. When it’s called the operator has already been cloned and it will
never be cloned again. Therefore it’s safe to store replica-specific metadata inside of it. Read moreSource§fn next(&mut self) -> StreamElement<Self::Out>
fn next(&mut self) -> StreamElement<Self::Out>
Take a value from the previous operator, process it and return it.
Source§fn structure(&self) -> BlockStructure
fn structure(&self) -> BlockStructure
A more refined representation of the operator and its predecessors.
Source§impl<S> Source for ParallelIteratorSource<S>
impl<S> Source for ParallelIteratorSource<S>
Source§fn replication(&self) -> Replication
fn replication(&self) -> Replication
The maximum parallelism offered by this operator.
Auto Trait Implementations§
impl<Source> Freeze for ParallelIteratorSource<Source>
impl<Source> RefUnwindSafe for ParallelIteratorSource<Source>
impl<Source> Send for ParallelIteratorSource<Source>
impl<Source> Sync for ParallelIteratorSource<Source>
impl<Source> Unpin for ParallelIteratorSource<Source>
impl<Source> UnwindSafe for ParallelIteratorSource<Source>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more