You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "blinding-pixels (via GitHub)" <gi...@apache.org> on 2026/09/01 06:05:30 UTC

Re: [PR] fix: avoid invalid qualifiers in unparsed subqueries [datafusion]

blinding-pixels commented on code in PR #24808:
URL: https://github.com/apache/datafusion/pull/24808#discussion_r3901231616


##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -451,6 +457,92 @@ impl Unparser<'_> {
         }
     }
 
+    /// Return the alias recursion would assign when `plan` must become a
+    /// derived relation below an already rendered projection.
+    fn derived_input_alias(plan: &LogicalPlan) -> Option<&'static str> {
+        match plan {
+            LogicalPlan::Projection(_) => Some("derived_projection"),
+            LogicalPlan::Limit(_) => Some("derived_limit"),
+            LogicalPlan::Sort(_) => Some("derived_sort"),
+            LogicalPlan::Distinct(_) => Some("derived_distinct"),
+            LogicalPlan::Filter(filter) => {
+                Self::derived_input_alias(filter.input.as_ref())
+            }
+            LogicalPlan::Repartition(repartition) => {
+                Self::derived_input_alias(repartition.input.as_ref())
+            }
+            _ => None,
+        }
+    }
+
+    fn derived_input_scope<'a>(
+        plan: &'a LogicalPlan,
+        select: &SelectBuilder,
+    ) -> Option<DerivedInputScope<'a>> {
+        if select.inside_subquery_alias() {
+            return None;
+        }
+
+        match plan {
+            LogicalPlan::Projection(projection) => {
+                let alias = Self::derived_input_alias(projection.input.as_ref())?;

Review Comment:
   Whoa, I totally missed that case. Is there any part of the codebase you would recommend digging into so I can get better at catching cases like this in the future?



-- 
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-unsubscribe@datafusion.apache.org

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


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