kumarUjjawal commented on code in PR #25549:
URL: https://github.com/apache/datafusion/pull/25549#discussion_r4115420708
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -1243,6 +1244,12 @@ impl Unparser<'_> {
select.selection(Some(filter_expr));
}
+ // if the inner plan aliases columns used by the filter, we
need to convert to a
+ // subquery to prevent invalid references
+ if filter_depends_on_input_alias(filter) {
Review Comment:
For `SELECT * FROM (SELECT a, random() AS x FROM t) WHERE x > a`, the
predicate retains the qualified t.a reference. The new subquery hides t, but
`derived_input_scope()` does not recognize this boundary, so that reference
remains outside its valid scope. Include the boundary in scope detection and
add a regression that replans the generated SQL.
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -1243,6 +1244,12 @@ impl Unparser<'_> {
select.selection(Some(filter_expr));
}
+ // if the inner plan aliases columns used by the filter, we
need to convert to a
+ // subquery to prevent invalid references
+ if filter_depends_on_input_alias(filter) {
+ return self.derive(&filter.input, relation, None, false);
Review Comment:
Calling derive(..., None, ...) bypasses requires_derived_table_alias(). This
produces an unnamed derived table even for MySqlDialect, which requires an
alias. Use the dialect-aware derivation helper and ensure predicate rebasing
uses the same alias. Add dialect coverage alongside the default-dialect tests.
--
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]