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