forked from KipData/KiteSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.rs
More file actions
53 lines (46 loc) · 1.69 KB
/
filter.rs
File metadata and controls
53 lines (46 loc) · 1.69 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
use crate::execution::{build_read, Executor, ReadExecutor};
use crate::expression::ScalarExpression;
use crate::planner::operator::filter::FilterOperator;
use crate::planner::LogicalPlan;
use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache};
use crate::throw;
use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::Pin;
pub struct Filter {
predicate: ScalarExpression,
input: LogicalPlan,
}
impl From<(FilterOperator, LogicalPlan)> for Filter {
fn from((FilterOperator { predicate, .. }, input): (FilterOperator, LogicalPlan)) -> Self {
Filter { predicate, input }
}
}
impl<'a, T: Transaction + 'a> ReadExecutor<'a, T> for Filter {
fn execute(
self,
cache: (&'a TableCache, &'a ViewCache, &'a StatisticsMetaCache),
transaction: *mut T,
) -> Executor<'a> {
Box::new(
#[coroutine]
move || {
let Filter {
predicate,
mut input,
} = self;
let schema = input.output_schema().clone();
//println!("{:#?}114514'\n'1919810{:#?}",predicate,schema);
let mut coroutine = build_read(input, cache, transaction);
while let CoroutineState::Yielded(tuple) = Pin::new(&mut coroutine).resume(()) {
let tuple = throw!(tuple);
//println!("-> Coroutine returned: {:?}", tuple);
if throw!(throw!(predicate.eval(Some((&tuple, &schema)))).is_true()) {
//println!("-> throw!: {:?}", tuple);
yield Ok(tuple);
}
}
},
)
}
}