xudong963 commented on a change in pull request #1067:
URL: https://github.com/apache/arrow-datafusion/pull/1067#discussion_r724698342
##########
File path: datafusion/src/sql/planner.rs
##########
@@ -528,21 +528,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".to_string(),
+ ));
+ }
+ 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();
+ let mut df_fields_with_alias = Vec::new();
+ for df_field in schema.fields().iter() {
+ let df_field_with_alias = DFField::from_qualified(
+ &alias.as_ref().unwrap().name.value,
+ df_field.field().clone(),
+ );
+ df_fields_with_alias.push(df_field_with_alias);
+ }
Review comment:
good sight!
--
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]