Skip to main content

reifydb_engine/flow/compiler/operator/
sort.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_core::{interface::catalog::flow::FlowNodeId, sort::SortKey};
5use reifydb_rql::{flow::node::FlowNodeType::Sort, nodes::SortNode, query::QueryPlan};
6use reifydb_transaction::transaction::admin::AdminTransaction;
7use reifydb_type::Result;
8
9use crate::flow::compiler::{CompileOperator, FlowCompiler};
10
11pub(crate) struct SortCompiler {
12	pub input: Box<QueryPlan>,
13	pub by: Vec<SortKey>,
14}
15
16impl From<SortNode> for SortCompiler {
17	fn from(node: SortNode) -> Self {
18		Self {
19			input: node.input,
20			by: node.by,
21		}
22	}
23}
24
25impl CompileOperator for SortCompiler {
26	fn compile(self, compiler: &mut FlowCompiler, txn: &mut AdminTransaction) -> Result<FlowNodeId> {
27		let input_node = compiler.compile_plan(txn, *self.input)?;
28
29		let node_id = compiler.add_node(
30			txn,
31			Sort {
32				by: self.by,
33			},
34		)?;
35
36		compiler.add_edge(txn, &input_node, &node_id)?;
37		Ok(node_id)
38	}
39}