houqp commented on a change in pull request #1067:
URL: https://github.com/apache/arrow-datafusion/pull/1067#discussion_r724695469
##########
File path: datafusion/src/sql/planner.rs
##########
@@ -565,14 +587,22 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
)));
} else {
let fields = plan.schema().fields().clone();
- LogicalPlanBuilder::from(plan)
- .project(
+ let plan = LogicalPlanBuilder::from(plan)
+ .project_with_alias(
fields
.iter()
.zip(columns_alias.iter())
- .map(|(field, ident)|
col(field.name()).alias(&ident.value)),
+ .map(|(field, ident)| {
+ col_with_table_name(
+ field.name(),
+ &*(alias.clone().name.value),
+ )
+ .alias(ident.value.as_str())
+ }),
Review comment:
After taking a closer look at the code, I now agree with @alamb that we
don't need to do a 2nd round of patching here. The `fields` comes from
`plan.schema().fields()`. The schema for the plan we referenced here has
already been patched in the previous relation match block.
##########
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:
it looks like `df_fields_with_alias` is not being used anymore? the
schema patching should have been covered by `project_with_alias` right?
--
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]