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


##########
datafusion/optimizer/src/scalar_subquery_to_join.rs:
##########
@@ -71,19 +71,36 @@ impl ScalarSubqueryToJoin {
 impl OptimizerRule for ScalarSubqueryToJoin {
     fn try_optimize(
         &self,
-        plan: &LogicalPlan,
-        config: &dyn OptimizerConfig,
+        _plan: &LogicalPlan,
+        _config: &dyn OptimizerConfig,
     ) -> Result<Option<LogicalPlan>> {
+        internal_err!("Should have called ScalarSubqueryToJoin::rewrite")
+    }
+
+    fn supports_rewrite(&self) -> bool {
+        true
+    }
+
+    fn rewrite(
+        &self,
+        plan: LogicalPlan,
+        config: &dyn OptimizerConfig,
+    ) -> Result<Transformed<LogicalPlan>> {
         match plan {
             LogicalPlan::Filter(filter) => {
+                // Optimization: skip the rest of the rule and its copies if

Review Comment:
   Note there is a still a bunch of copying in the actual rewrite logic itself 
below, but I could not figure out a way to remove it easily as there are 
several paths that return the original (unmodified) plan for unsupported 
subqueries
   
   I think we would have to split the check for "is rewrite supported" and the 
"do the rewrite" logic or something
   
   Given this isn't a tall pole in planning, I don't have any more time to 
spend on this particular rule so I want to call this good enough
   



##########
datafusion/optimizer/src/scalar_subquery_to_join.rs:
##########
@@ -94,16 +111,13 @@ impl OptimizerRule for ScalarSubqueryToJoin {
                     {
                         if !expr_check_map.is_empty() {
                             rewrite_expr = rewrite_expr
-                                .clone()
                                 .transform_up(|expr| {
-                                    if let Expr::Column(col) = &expr {
-                                        if let Some(map_expr) =
-                                            expr_check_map.get(&col.name)
-                                        {
-                                            
Ok(Transformed::yes(map_expr.clone()))
-                                        } else {
-                                            Ok(Transformed::no(expr))
-                                        }
+                                    // replace column references with entry in 
map, if it exists

Review Comment:
   Remove some indenting using the api added in 
https://github.com/apache/datafusion/pull/10448, but the logic is the same



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to