use nodedb_physical::physical_plan::PhysicalPlan;
use nodedb_types::result::QueryResult;
use crate::error::LiteError;
use crate::query::engine::LiteQueryEngine;
use crate::query::physical_visitor::LiteDataPlaneVisitor;
use crate::storage::engine::StorageEngine;
pub async fn execute_plans_in_order<S: StorageEngine>(
engine: &LiteQueryEngine<S>,
plans: &[PhysicalPlan],
) -> Result<QueryResult, LiteError> {
let mut last = QueryResult::empty();
for plan in plans {
let mut visitor = LiteDataPlaneVisitor::new(engine);
let fut = nodedb_physical::dispatch(&mut visitor, plan)?;
last = fut.await?;
}
Ok(last)
}
pub async fn handle_txn_batch<S: StorageEngine>(
engine: &LiteQueryEngine<S>,
plans: &[PhysicalPlan],
) -> Result<QueryResult, LiteError> {
execute_plans_in_order(engine, plans).await
}
pub async fn handle_calvin_static<S: StorageEngine>(
engine: &LiteQueryEngine<S>,
plans: &[PhysicalPlan],
) -> Result<QueryResult, LiteError> {
execute_plans_in_order(engine, plans).await
}
pub async fn handle_calvin_passive() -> Result<QueryResult, LiteError> {
Ok(QueryResult::empty())
}
pub async fn handle_calvin_active<S: StorageEngine>(
engine: &LiteQueryEngine<S>,
plans: &[PhysicalPlan],
) -> Result<QueryResult, LiteError> {
execute_plans_in_order(engine, plans).await
}
#[cfg(test)]
mod tests {
use super::*;
use nodedb_physical::physical_plan::{MetaOp, PhysicalPlan};
#[tokio::test]
async fn txn_batch_empty_plans_ok() {
let plans: Vec<PhysicalPlan> = vec![];
let checkpoint = PhysicalPlan::Meta(MetaOp::Checkpoint);
assert_eq!(plans.len(), 0);
let _ = checkpoint.clone();
}
#[test]
fn calvin_passive_is_empty() {
let _fut = handle_calvin_passive();
}
}