houqp commented on a change in pull request #1067:
URL: https://github.com/apache/arrow-datafusion/pull/1067#discussion_r721721686



##########
File path: datafusion/src/sql/planner.rs
##########
@@ -522,21 +521,43 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                             name
                         ))),
                     }?,
-                    columns_alias,
+                    alias,
                 )
             }
             TableFactor::Derived {
                 subquery, alias, ..
-            } => (
-                self.query_to_plan_with_alias(
+            } => {
+                // if alias is None, return Err
+                if alias.is_none() {
+                    return Err(DataFusionError::Plan(
+                        "subquery in FROM must have an alias".parse().unwrap(),
+                    ));
+                }
+                let logical_plan = self.query_to_plan_with_alias(
                     subquery,
                     alias.as_ref().map(|a| a.name.value.to_string()),
                     ctes,
-                )?,
-                alias.clone().map(|x| x.columns),
-            ),
+                )?;
+                let schema = logical_plan.schema();

Review comment:
       My guess is the projection won't work if the schema is still referencing 
the original qualifier, i.e. projection asked for `b.id`, but the input plan 
schema only has `customer.id`, resulting in runtime error.




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


Reply via email to