peter-toth commented on code in PR #10473:
URL: https://github.com/apache/datafusion/pull/10473#discussion_r1604625075


##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -782,31 +819,31 @@ impl TreeNodeRewriter for CommonSubexprRewriter<'_> {
             return Ok(Transformed::new(expr, false, TreeNodeRecursion::Jump));
         }
 
-        let (up_index, expr_id) = &self.id_array[self.down_index];
+        let (up_index, expr_id) = self.id_array[self.down_index];
         self.down_index += 1;
 
         // skip `Expr`s without identifier (empty identifier).
-        if expr_id.is_empty() {
+        let Some(expr_id) = expr_id else {
             return Ok(Transformed::no(expr));
-        }
+        };
 
-        let (counter, _) = self.expr_stats.get(expr_id).unwrap();
-        if *counter > 1 {
+        let (count, _) = self.expr_stats.get(&expr_id).unwrap();
+        if *count > 1 {
             // step index to skip all sub-node (which has smaller series 
number).
             while self.down_index < self.id_array.len()
-                && self.id_array[self.down_index].0 < *up_index
+                && self.id_array[self.down_index].0 < up_index
             {
                 self.down_index += 1;
             }
 
             let expr_name = expr.display_name()?;
-            self.common_exprs.insert(expr_id.clone(), expr);
+            self.common_exprs.insert(expr_id, expr);
             // Alias this `Column` expr to it original "expr name",
             // `projection_push_down` optimizer use "expr name" to eliminate 
useless
             // projections.
             // TODO: do we really need to alias here?

Review Comment:
   As far as I know we still don't know why this alias is exactly needed. 
Please see this thread here: 
https://github.com/apache/datafusion/pull/10396#discussion_r1592927865. I 
suspect that it is not needed in all cases...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to