This method mutates an expression node by transforming it to a physical expression and adding it to the graph. The method returns the mutated expression node.
(
&mut self,
mut node: ExprTreeNode<NodeIndex>,
)
| 231 | // This method mutates an expression node by transforming it to a physical expression |
| 232 | // and adding it to the graph. The method returns the mutated expression node. |
| 233 | fn mutate( |
| 234 | &mut self, |
| 235 | mut node: ExprTreeNode<NodeIndex>, |
| 236 | ) -> Result<Transformed<ExprTreeNode<NodeIndex>>> { |
| 237 | // Get the expression associated with the input expression node. |
| 238 | let expr = &node.expr; |
| 239 | |
| 240 | // Check if the expression has already been visited. |
| 241 | let node_idx = match self.visited_plans.iter().find(|(e, _)| expr.eq(e)) { |
| 242 | // If the expression has been visited, return the corresponding node index. |
| 243 | Some((_, idx)) => *idx, |
| 244 | // If the expression has not been visited, add a new node to the graph and |
| 245 | // add edges to its child nodes. Add the visited expression to the vector |
| 246 | // of visited expressions and return the newly created node index. |
| 247 | None => { |
| 248 | let node_idx = self.graph.add_node((self.constructor)(&node)?); |
| 249 | for expr_node in node.children.iter() { |
| 250 | self.graph.add_edge(node_idx, expr_node.data.unwrap(), 0); |
| 251 | } |
| 252 | self.visited_plans.push((Arc::clone(expr), node_idx)); |
| 253 | node_idx |
| 254 | } |
| 255 | }; |
| 256 | // Set the data field of the input expression node to the corresponding node index. |
| 257 | node.data = Some(node_idx); |
| 258 | // Return the mutated expression node. |
| 259 | Ok(Transformed::yes(node)) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // A function that builds a directed acyclic graph of physical expression trees. |