use crate::execution::volcano::{BoxedExecutor, Executor};
use crate::execution::ExecutorError;
use crate::planner::operator::scan::ScanOperator;
use crate::storage::{Iter, Transaction};
use crate::types::tuple::Tuple;
use futures_async_stream::try_stream;
use std::cell::RefCell;
pub(crate) struct SeqScan {
op: ScanOperator,
}
impl From<ScanOperator> for SeqScan {
fn from(op: ScanOperator) -> Self {
SeqScan { op }
}
}
impl<T: Transaction> Executor<T> for SeqScan {
fn execute(self, transaction: &RefCell<T>) -> BoxedExecutor {
unsafe { self._execute(transaction.as_ptr().as_ref().unwrap()) }
}
}
impl SeqScan {
#[try_stream(boxed, ok = Tuple, error = ExecutorError)]
pub async fn _execute<T: Transaction>(self, transaction: &T) {
let ScanOperator {
table_name,
columns,
limit,
..
} = self.op;
let mut iter = transaction.read(table_name, limit, columns)?;
while let Some(tuple) = iter.next_tuple()? {
yield tuple;
}
}
}