alamb commented on code in PR #10165:
URL: https://github.com/apache/datafusion/pull/10165#discussion_r1575341213


##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -67,66 +88,97 @@ impl OptimizerRule for ExtractEquijoinPredicate {
             }) => {

Review Comment:
   You might be able to avoid a level of indenting if you did the entire match 
here, like:
   
   ```
    match plan {
               LogicalPlan::Join(Join {
                   left,
                   right,
                   mut on,
                   filter: Some(expr),
                   join_type,
                   join_constraint,
               }) => {
   ```
   
   Then you could avoid reassembling LogicalPlan::Join as well



##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -67,69 +88,100 @@ impl OptimizerRule for ExtractEquijoinPredicate {
             }) => {
                 let left_schema = left.schema();
                 let right_schema = right.schema();
-
-                filter.as_ref().map_or(Result::Ok(None), |expr| {
+                if let Some(expr) = filter {
                     let (equijoin_predicates, non_equijoin_expr) =
                         split_eq_and_noneq_join_predicate(
                             expr,
                             left_schema,
                             right_schema,
                         )?;
 
-                    let optimized_plan = 
(!equijoin_predicates.is_empty()).then(|| {
-                        let mut new_on = on.clone();
-                        new_on.extend(equijoin_predicates);
-
-                        LogicalPlan::Join(Join {
-                            left: left.clone(),
-                            right: right.clone(),
-                            on: new_on,
+                    if !equijoin_predicates.is_empty() {
+                        on.extend(equijoin_predicates);
+                        Ok(Transformed::yes(LogicalPlan::Join(Join {
+                            left,
+                            right,
+                            on,
+                            filter: non_equijoin_expr,
+                            join_type,
+                            join_constraint,
+                            schema,
+                            null_equals_null,
+                        })))
+                    } else {
+                        Ok(Transformed::no(LogicalPlan::Join(Join {
+                            left,
+                            right,
+                            on,
                             filter: non_equijoin_expr,
-                            join_type: *join_type,
-                            join_constraint: *join_constraint,
-                            schema: schema.clone(),
-                            null_equals_null: *null_equals_null,
-                        })
-                    });
-
-                    Ok(optimized_plan)
-                })
+                            join_type,
+                            join_constraint,
+                            schema,
+                            null_equals_null,
+                        })))
+                    }
+                } else {
+                    Ok(Transformed::no(LogicalPlan::Join(Join {
+                        left,
+                        right,
+                        on,
+                        filter,
+                        join_type,
+                        join_constraint,
+                        schema,
+                        null_equals_null,
+                    })))
+                }
             }
-            _ => Ok(None),
+            _ => Ok(Transformed::no(plan)),
         }
     }
+}
 
-    fn name(&self) -> &str {
-        "extract_equijoin_predicate"
-    }
+/// split with ownership
+fn split_conjunction_own(expr: Expr) -> Vec<Expr> {

Review Comment:
   I think there is already a function that does this: 
https://docs.rs/datafusion/latest/datafusion/logical_expr/utils/fn.split_conjunction_owned.html



-- 
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