forked from KipData/KiteSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcept.rs
More file actions
58 lines (50 loc) · 1.7 KB
/
except.rs
File metadata and controls
58 lines (50 loc) · 1.7 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
use crate::execution::{build_read, Executor, ReadExecutor};
use crate::planner::LogicalPlan;
use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache};
use crate::throw;
use ahash::{HashSet, HashSetExt};
use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::Pin;
pub struct Except {
left_input: LogicalPlan,
right_input: LogicalPlan,
}
impl From<(LogicalPlan, LogicalPlan)> for Except {
fn from((left_input, right_input): (LogicalPlan, LogicalPlan)) -> Self {
Except {
left_input,
right_input,
}
}
}
impl<'a, T: Transaction + 'a> ReadExecutor<'a, T> for Except {
fn execute(
self,
cache: (&'a TableCache, &'a ViewCache, &'a StatisticsMetaCache),
transaction: *mut T,
) -> Executor<'a> {
Box::new(
#[coroutine]
move || {
let Except {
left_input,
right_input,
} = self;
let mut coroutine = build_read(right_input, cache, transaction);
let mut except_col = HashSet::new();
while let CoroutineState::Yielded(tuple) = Pin::new(&mut coroutine).resume(()) {
let tuple = throw!(tuple);
except_col.insert(tuple);
}
let mut coroutine = build_read(left_input, cache, transaction);
while let CoroutineState::Yielded(tuple) = Pin::new(&mut coroutine).resume(()) {
let tuple = throw!(tuple);
if !except_col.contains(&tuple) {
yield Ok(tuple);
}
}
},
)
}
}