use crate::{
Result,
engine::{exec::Exec, mir, mir::LogicalPlan},
};
#[derive(Debug)]
pub(crate) struct If {
pub(crate) then: Vec<mir::NodeId>,
pub(crate) skipped_inputs: Vec<mir::NodeId>,
pub(crate) skipped_outputs: Vec<(mir::NodeId, usize)>,
}
impl If {
fn guard(&self, logical_plan: &LogicalPlan) -> mir::NodeId {
logical_plan[self.then[0]]
.guard
.expect("`If` block nodes carry the block's guard")
}
}
impl Exec<'_> {
pub(super) async fn action_if(
&mut self,
logical_plan: &LogicalPlan,
action: &If,
) -> Result<()> {
let cond = action.guard(logical_plan);
let pass = self.vars.peek_non_empty(cond).await?;
if pass {
for &node_id in &action.then {
self.exec_node(logical_plan, node_id).await?;
}
} else {
for &node_id in &action.skipped_inputs {
self.vars.release(node_id);
}
for &(node_id, num_uses) in &action.skipped_outputs {
self.vars.store_skipped(node_id, num_uses);
}
}
Ok(())
}
}