reifydb_engine/flow/compiler/operator/
take.rs1use reifydb_core::interface::catalog::flow::FlowNodeId;
5use reifydb_rql::{flow::node::FlowNodeType::Take, nodes::TakeNode, query::QueryPlan};
6use reifydb_transaction::transaction::admin::AdminTransaction;
7use reifydb_type::Result;
8
9use crate::flow::compiler::{CompileOperator, FlowCompiler};
10
11pub(crate) struct TakeCompiler {
12 pub input: Box<QueryPlan>,
13 pub limit: usize,
14}
15
16impl From<TakeNode> for TakeCompiler {
17 fn from(node: TakeNode) -> Self {
18 Self {
19 input: node.input,
20 limit: node.take,
21 }
22 }
23}
24
25impl CompileOperator for TakeCompiler {
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 Take {
32 limit: self.limit,
33 },
34 )?;
35
36 compiler.add_edge(txn, &input_node, &node_id)?;
37 Ok(node_id)
38 }
39}