diff --git a/src/ir/expression.rs b/src/ir/expression.rs index 9c23ed25398244928da978631737035e0503fb5b..850d5c9147fd3c9d7cfefbf9faef1db812507725 100644 --- a/src/ir/expression.rs +++ b/src/ir/expression.rs @@ -885,70 +885,6 @@ impl Plan { } Ok(()) } - - /// Clone an expression tree. - /// - /// # Errors - /// - Node is not an expression. - /// - Internal errors during the expression tree copy. - pub fn expr_clone(&mut self, expr_id: usize) -> Result<usize, QueryPlannerError> { - let subtree = DftPost::new(&expr_id, |node| self.nodes.expr_iter(node, false)); - let nodes: Vec<usize> = subtree.map(|(_, id)| *id).collect(); - let mut map: HashMap<usize, usize> = HashMap::with_capacity(nodes.len()); - for id in nodes { - let expr = self.get_expression_node(id)?; - let new_id = match expr { - Expression::Alias { .. } - | Expression::Constant { .. } - | Expression::Reference { .. } => self.nodes.push(Node::Expression(expr.clone())), - Expression::Bool { left, op, right } => { - let new_left_id = *map.get(left).ok_or_else(|| { - QueryPlannerError::CustomError(format!( - "Left child of bool node {} wasn't found in the clone map", - id - )) - })?; - let new_right_id = *map.get(right).ok_or_else(|| { - QueryPlannerError::CustomError(format!( - "Right child of bool node {} wasn't found in the clone map", - id - )) - })?; - self.nodes.add_bool(new_left_id, op.clone(), new_right_id)? - } - Expression::Row { list, distribution } => { - let mut new_list: Vec<usize> = Vec::with_capacity(list.len()); - for column_id in list { - let new_column_id = *map.get(column_id).ok_or_else(|| { - QueryPlannerError::CustomError(format!( - "Row column node {} wasn't found in the clone map", - id - )) - })?; - new_list.push(new_column_id); - } - self.nodes.add_row(new_list, distribution.clone()) - } - Expression::Unary { op, child } => { - let new_child_id = *map.get(child).ok_or_else(|| { - QueryPlannerError::CustomError(format!( - "Child of unary node {} wasn't found in the clone map", - id - )) - })?; - self.nodes.add_unary_bool(op.clone(), new_child_id)? - } - }; - map.insert(id, new_id); - } - let new_expr_id = *map.get(&expr_id).ok_or_else(|| { - QueryPlannerError::CustomError(format!( - "Expression node {} wasn't found in the clone map", - expr_id - )) - })?; - Ok(new_expr_id) - } } #[cfg(test)] diff --git a/src/ir/transformation/bool_in.rs b/src/ir/transformation/bool_in.rs index 92fe73357d386368b918352b204aa1c491b1ca13..3a4ace0ba8e5d273408cf29d94321133972ab727 100644 --- a/src/ir/transformation/bool_in.rs +++ b/src/ir/transformation/bool_in.rs @@ -52,7 +52,7 @@ impl Plan { let right_columns = self.get_expression_node(right_id)?.clone_row_list()?; if let Some((first_id, other)) = right_columns.split_first() { - let new_left_id = self.expr_clone(left_id)?; + let new_left_id = left_id; let first_expr = self.get_expression_node(*first_id)?; let mut top_id = if first_expr.is_row() { diff --git a/src/ir/transformation/split_columns.rs b/src/ir/transformation/split_columns.rs index f8997503f70db4ff9fb20016bc5520ab029c81c2..00c0d7de44eada9a0fb8caa4463586a7d2304274 100644 --- a/src/ir/transformation/split_columns.rs +++ b/src/ir/transformation/split_columns.rs @@ -83,15 +83,15 @@ impl Plan { .map(|(l, r)| (*l, *r)) .collect::<Vec<_>>(); if let Some((first, other)) = pairs.split_first() { - let left_col_id = self.expr_clone(first.0)?; - let right_col_id = self.expr_clone(first.1)?; + let left_col_id = first.0; + let right_col_id = first.1; let left_row_id = self.nodes.add_row(vec![left_col_id], None); let right_row_id = self.nodes.add_row(vec![right_col_id], None); let mut top_id = self.add_cond(left_row_id, op.clone(), right_row_id)?; for (left_col_id, right_col_id) in other { - let left_col_id = self.expr_clone(*left_col_id)?; - let right_col_id = self.expr_clone(*right_col_id)?; + let left_col_id = *left_col_id; + let right_col_id = *right_col_id; let left_row_id = self.nodes.add_row(vec![left_col_id], None); let right_row_id = self.nodes.add_row(vec![right_col_id], None); let new_top_id = self.add_cond(left_row_id, op.clone(), right_row_id)?;