Skip to main content

reifydb_engine/flow/compiler/operator/
gate.rs

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