phillipleblanc opened a new issue, #16147:
URL: https://github.com/apache/datafusion/issues/16147

   ### Describe the bug
   
   The TreeNode implementation for `Expr` does not handle the 
`outer_ref_column` expressions present in the `Subquery` nodes of 
`Expr::InSubquery`, `Expr::ScalarSubquery`, and `Expr::Exists`.
   
   The LogicalPlan::map_expressions implementation does not handle the 
`outer_ref_column` expression in `LogicalPlan::Subquery`
   
   ### To Reproduce
   
   Create a LogicalPlan from a SQL statement with a subquery expression that 
has an outer column reference, i.e. 
   
   ```
   SELECT 
       e.employee_id,
       e.first_name,
       e.salary
   FROM 
       employees e
   WHERE 
       e.salary > (
           SELECT AVG(salary)
           FROM employees e2
           WHERE e2.department_id = e.department_id
       );
   ```
   
   I would expect to be able to do something like this:
   
   ```rust
   let plan = sql_to_plan(sql);
   plan.apply(|plan| {
     plan.apply_expressions(|expr| {
       match expr {
         Expr::OuterReferenceColumn(_, _) => { do something useful }
         _ => Ok(Transformed::no(expr))
       }
     });
   });
   ```
   
   ### Expected behavior
   
   The `outer_ref_column` expressions are part of the TreeNode visitor 
implementations in both Expr and LogicalPlan
   
   ### Additional context
   
   I will not work on this, so someone should feel free to take this. There is 
a workaround if you know about this behavior, which is to match on the 
expressions/plans which contain these outer ref column expressions.


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