1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Methods to construct generic streaming and blocking unary operators.
use crate::dataflow::operators::generic::{Notificator, FrontierNotificator};
use crate::dataflow::channels::pushers::Tee;
use crate::dataflow::channels::pact::ParallelizationContract;
use crate::dataflow::operators::generic::Operator as GenericOperator;
use crate::dataflow::operators::generic::handles::{InputHandle, OutputHandle};
use crate::Data;
use crate::dataflow::{Stream, Scope};
/// Methods to construct generic streaming and blocking unary operators.
pub trait Unary<G: Scope, D1: Data> {
/// Creates a new dataflow operator that partitions its input stream by a parallelization
/// strategy `pact`, and repeatedly invokes `logic` which can read from the input stream and
/// write to the output stream.
///
/// # Examples
/// ```
/// use timely::dataflow::operators::ToStream;
/// use timely::dataflow::operators::generic::unary::Unary;
/// use timely::dataflow::channels::pact::Pipeline;
///
/// timely::example(|scope| {
/// let mut vector = Vec::new();
/// (0..10).to_stream(scope)
/// .unary_stream(Pipeline, "example", move |input, output| {
/// input.for_each(|time, data| {
/// data.swap(&mut vector);
/// output.session(&time).give_vec(&mut vector);
/// });
/// });
/// });
/// ```
#[deprecated(since="0.5", note="please use `Operator`'s `unary` method directly")]
fn unary_stream<D2, L, P> (&self, pact: P, name: &str, logic: L) -> Stream<G, D2>
where
D2: Data,
L: FnMut(&mut InputHandle<G::Timestamp, D1, P::Puller>,
&mut OutputHandle<G::Timestamp, D2, Tee<G::Timestamp, D2>>)+'static,
P: ParallelizationContract<G::Timestamp, D1>;
/// Creates a new dataflow operator that partitions its input stream by a parallelization
/// strategy `pact`, and repeatedly invokes `logic` which can read from the input stream,
/// write to the output stream, and request and receive notifications. The method also requires
/// a vector of the initial notifications the operator requires (commonly none).
///
/// # Examples
/// ```
/// use timely::dataflow::operators::ToStream;
/// use timely::dataflow::operators::generic::unary::Unary;
/// use timely::dataflow::channels::pact::Pipeline;
///
/// timely::example(|scope| {
/// let mut vector = Vec::new();
/// (0..10).to_stream(scope)
/// .unary_notify(Pipeline, "example", Vec::new(), move |input, output, notificator| {
/// input.for_each(|time, data| {
/// data.swap(&mut vector);
/// output.session(&time).give_vec(&mut vector);
/// notificator.notify_at(time.retain());
/// });
/// notificator.for_each(|time,_,_| {
/// println!("done with time: {:?}", time.time());
/// });
/// });
/// });
/// ```
#[deprecated(since="0.5", note="please use `Operator`'s `unary_notify` method directly")]
fn unary_notify<D2, L, P>(&self, pact: P, name: &str, init: Vec<G::Timestamp>, logic: L) -> Stream<G, D2>
where
D2: Data,
L: FnMut(&mut InputHandle<G::Timestamp, D1, P::Puller>,
&mut OutputHandle<G::Timestamp, D2, Tee<G::Timestamp, D2>>,
&mut Notificator<G::Timestamp>)+'static,
P: ParallelizationContract<G::Timestamp, D1>;
}
impl<G: Scope, D1: Data> Unary<G, D1> for Stream<G, D1> {
fn unary_notify<D2: Data,
L: FnMut(&mut InputHandle<G::Timestamp, D1, P::Puller>,
&mut OutputHandle<G::Timestamp, D2, Tee<G::Timestamp, D2>>,
&mut Notificator<G::Timestamp>)+'static,
P: ParallelizationContract<G::Timestamp, D1>>
(&self, pact: P, name: &str, init: Vec<G::Timestamp>, mut logic: L) -> Stream<G, D2> {
self.unary_frontier(pact, name, move |capability, _info| {
let mut notificator = FrontierNotificator::new();
for time in init {
notificator.notify_at(capability.delayed(&time));
}
let logging = self.scope().logging();
move |input, output| {
let frontier = &[input.frontier()];
let notificator = &mut Notificator::new(frontier, &mut notificator, &logging);
logic(&mut input.handle, output, notificator);
}
})
}
fn unary_stream<D2: Data,
L: FnMut(&mut InputHandle<G::Timestamp, D1, P::Puller>,
&mut OutputHandle<G::Timestamp, D2, Tee<G::Timestamp, D2>>)+'static,
P: ParallelizationContract<G::Timestamp, D1>>
(&self, pact: P, name: &str, logic: L) -> Stream<G, D2> {
self.unary(pact, name, |_, _| logic)
}
}