use reifydb_core::interface::catalog::flow::FlowNodeId;
use reifydb_rql::{expression::Expression, flow::node::FlowNodeType::Extend, nodes::ExtendNode, query::QueryPlan};
use reifydb_transaction::transaction::Transaction;
use reifydb_type::Result;
use crate::flow::compiler::{CompileOperator, FlowCompiler};
pub(crate) struct ExtendCompiler {
pub input: Option<Box<QueryPlan>>,
pub expressions: Vec<Expression>,
}
impl From<ExtendNode> for ExtendCompiler {
fn from(node: ExtendNode) -> Self {
Self {
input: node.input,
expressions: node.extend,
}
}
}
impl CompileOperator for ExtendCompiler {
fn compile(self, compiler: &mut FlowCompiler, txn: &mut Transaction<'_>) -> Result<FlowNodeId> {
let input_node = if let Some(input) = self.input {
Some(compiler.compile_plan(txn, *input)?)
} else {
None
};
let node_id = compiler.add_node(
txn,
Extend {
expressions: self.expressions,
},
)?;
if let Some(input) = input_node {
compiler.add_edge(txn, &input, &node_id)?;
}
Ok(node_id)
}
}