reifydb_engine/flow/compiler/operator/
apply.rs1use reifydb_core::interface::catalog::flow::FlowNodeId;
5use reifydb_rql::{expression::Expression, flow::node::FlowNodeType::Apply, nodes::ApplyNode, query::QueryPlan};
6use reifydb_transaction::transaction::admin::AdminTransaction;
7use reifydb_type::{Result, fragment::Fragment};
8
9use crate::flow::compiler::{CompileOperator, FlowCompiler};
10
11pub(crate) struct ApplyCompiler {
12 pub input: Option<Box<QueryPlan>>,
13 pub operator: Fragment,
14 pub arguments: Vec<Expression>,
15}
16
17impl From<ApplyNode> for ApplyCompiler {
18 fn from(node: ApplyNode) -> Self {
19 Self {
20 input: node.input,
21 operator: node.operator,
22 arguments: node.expressions,
23 }
24 }
25}
26
27impl CompileOperator for ApplyCompiler {
28 fn compile(self, compiler: &mut FlowCompiler, txn: &mut AdminTransaction) -> Result<FlowNodeId> {
29 let input_node = if let Some(input) = self.input {
30 Some(compiler.compile_plan(txn, *input)?)
31 } else {
32 None
33 };
34
35 let node_id = compiler.add_node(
36 txn,
37 Apply {
38 operator: self.operator.text().to_string(),
39 expressions: self.arguments,
40 },
41 )?;
42
43 if let Some(input) = input_node {
44 compiler.add_edge(txn, &input, &node_id)?;
45 }
46
47 Ok(node_id)
48 }
49}