abp002 opened a new pull request, #26596:
URL: https://github.com/apache/datafusion/pull/26596

   ## Which issue does this PR close?
   
   - Closes #26573.
   
   ## Rationale for this change
   
   A subquery in a `JOIN ... ON` that correlates on an aliased table fails to 
plan with `No field named x.a`. This is not specific to `= ANY`: `EXISTS (... 
WHERE s.b = x.a)` and a correlated `IN` in the same place fail the same way.
   
   The `ON` predicate ends up in a `Filter` that `push_down_filter` pushes 
through `SubqueryAlias: x`. `replace_cols_by_name` rewrites `x.a` to `t.a` in 
the columns of the predicate, but not in the outer references of its 
subqueries, so below the alias they name `x.a`, which no longer exists.
   
   ## What changes are included in this PR?
   
   When pushing a filter through a `SubqueryAlias`, the conjuncts with a 
subquery correlated on a column of the alias stay above it, and the rest is 
pushed down as before. `decorrelate_predicate_subquery` then turns them into a 
join above the alias. A subquery correlated only on columns from further out is 
still pushed.
   
   ## What is the testing strategy for this PR?
   
   New `subquery_alias_outer_referenced_column` in `push_down_filter.rs`, which 
fails without the fix, and `subquery.slt` cases for `= ANY`, `> ALL` and 
`EXISTS` in a `JOIN ... ON` over an aliased table.
   
   ## Are there any user-facing changes?
   
   No.
   


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