use indexmap::IndexSet;
use toasty_core::stmt;
use crate::engine::{
exec,
mir::{self, LogicalPlan},
};
#[derive(Debug)]
pub(crate) struct Upsert {
pub(crate) inputs: IndexSet<mir::NodeId>,
pub(crate) stmt: stmt::Insert,
pub(crate) ty: stmt::Type,
}
impl Upsert {
pub(crate) fn to_exec(
&self,
logical_plan: &LogicalPlan,
node: &mir::Node,
var_table: &mut exec::VarDecls,
) -> exec::Upsert {
let input = self
.inputs
.iter()
.map(|input| logical_plan[input].var.get().unwrap())
.collect();
let output = var_table.register_var(self.ty.clone());
node.var.set(Some(output));
exec::Upsert {
input,
output: exec::Output {
var: output,
num_uses: node.num_uses.get(),
},
stmt: self.stmt.clone(),
ret: mir::row_field_types(&self.ty),
}
}
}
impl From<Upsert> for mir::Node {
fn from(value: Upsert) -> Self {
mir::Operation::Upsert(Box::new(value)).into()
}
}