-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtransform_test.rs
More file actions
141 lines (122 loc) · 4.54 KB
/
transform_test.rs
File metadata and controls
141 lines (122 loc) · 4.54 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::collections::HashSet;
use std::iter::FromIterator;
use std::sync::mpsc::channel;
use std::time::Duration;
use timely::dataflow::channels::pact::Pipeline;
use timely::dataflow::operators::Operator;
use declarative_dataflow::binding::Binding;
use declarative_dataflow::plan::{Function, Implementable, Transform};
use declarative_dataflow::server::Server;
use declarative_dataflow::{Aid, AttributeConfig, Datom, InputSemantics, Plan, Rule, Value};
use Value::{Eid, Instant};
struct Case {
description: &'static str,
plan: Plan<Aid>,
transactions: Vec<Vec<Datom<Aid>>>,
expectations: Vec<Vec<(Vec<Value>, u64, isize)>>,
}
fn dependencies(case: &Case) -> HashSet<Aid> {
let mut deps = HashSet::new();
for binding in case.plan.into_bindings().iter() {
if let Binding::Attribute(binding) = binding {
deps.insert(binding.source_attribute.clone());
}
}
deps
}
#[test]
fn run_transform_cases() {
let mut cases = vec![Case {
description: "[:find ?h :where [?e :timestamp ?t] [(interval ?t) ?h]]",
plan: {
let (e, t, h) = (1, 2, 3);
let constants = vec![None, None];
// let constants = vec![None, Some(Value::String(String::from("hour")))];
Plan::Transform(Transform {
variables: vec![t],
result_variable: h,
plan: Box::new(Plan::match_a(e, ":timestamp", t)),
function: Function::TRUNCATE,
constants,
})
},
transactions: vec![vec![
Datom::add(1, ":timestamp", Instant(1_540_048_515_500)),
Datom::add(2, ":timestamp", Instant(1_540_048_515_616)),
]],
expectations: vec![vec![
(
vec![
Eid(1),
Instant(1_540_048_515_500),
Instant(1_540_047_600_000),
],
0,
1,
),
(
vec![
Eid(2),
Instant(1_540_048_515_616),
Instant(1_540_047_600_000),
],
0,
1,
),
]],
}];
for case in cases.drain(..) {
timely::execute_directly(move |worker| {
let mut server = Server::<Aid, u64, u64>::new(Default::default());
let (send_results, results) = channel();
dbg!(case.description);
let deps = dependencies(&case);
let plan = case.plan.clone();
worker.dataflow::<u64, _, _>(|scope| {
for dep in deps.into_iter() {
server
.create_attribute(scope, dep, AttributeConfig::tx_time(InputSemantics::Raw))
.unwrap();
}
server
.test_single(scope, Rule::named("hector", plan))
.inner
.sink(Pipeline, "Results", move |input| {
input.for_each(|_time, data| {
for datum in data.iter() {
send_results.send(datum.clone()).unwrap()
}
});
});
});
let mut transactions = case.transactions.clone();
let mut next_tx = 0;
for (tx_id, tx_data) in transactions.drain(..).enumerate() {
next_tx += 1;
server.transact(tx_data, 0, 0).unwrap();
server.advance_domain(None, next_tx).unwrap();
worker.step_while(|| server.is_any_outdated());
let mut expected: HashSet<(Vec<Value>, u64, isize)> =
HashSet::from_iter(case.expectations[tx_id].iter().cloned());
for _i in 0..expected.len() {
match results.recv_timeout(Duration::from_millis(400)) {
Err(_err) => {
panic!("No result.");
}
Ok(result) => {
if !expected.remove(&result) {
panic!("Unknown result {:?}.", result);
}
}
}
}
match results.recv_timeout(Duration::from_millis(400)) {
Err(_err) => {}
Ok(result) => {
panic!("Extraneous result {:?}", result);
}
}
}
});
}
}