use reifydb_core::{interface::catalog::flow::FlowNodeId, sort::SortKey};
use reifydb_rql::{flow::node::FlowNodeType::Sort, nodes::SortNode, query::QueryPlan};
use reifydb_transaction::transaction::Transaction;
use reifydb_type::Result;
use crate::flow::compiler::{CompileOperator, FlowCompiler};
pub(crate) struct SortCompiler {
pub input: Box<QueryPlan>,
pub by: Vec<SortKey>,
}
impl From<SortNode> for SortCompiler {
fn from(node: SortNode) -> Self {
Self {
input: node.input,
by: node.by,
}
}
}
impl CompileOperator for SortCompiler {
fn compile(self, compiler: &mut FlowCompiler, txn: &mut Transaction<'_>) -> Result<FlowNodeId> {
let input_node = compiler.compile_plan(txn, *self.input)?;
let node_id = compiler.add_node(
txn,
Sort {
by: self.by,
},
)?;
compiler.add_edge(txn, &input_node, &node_id)?;
Ok(node_id)
}
}