andygrove commented on code in PR #4484:
URL: https://github.com/apache/arrow-datafusion/pull/4484#discussion_r1039972466
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -978,26 +957,26 @@ pub fn project_with_alias(
plan.schema().metadata().clone(),
)?;
- let projection = LogicalPlan::Projection(Projection::try_new_with_schema(
+ Ok(LogicalPlan::Projection(Projection::try_new_with_schema(
projected_expr,
Arc::new(plan.clone()),
DFSchemaRef::new(input_schema),
- )?);
- match alias {
- Some(alias) => Ok(with_alias(projection, alias)),
- None => Ok(projection),
- }
+ )?))
}
/// Create a SubqueryAlias to wrap a LogicalPlan.
-pub fn with_alias(plan: LogicalPlan, alias: String) -> LogicalPlan {
- let plan_schema = &**plan.schema();
- let schema = (plan_schema.clone()).replace_qualifier(alias.as_str());
- LogicalPlan::SubqueryAlias(SubqueryAlias {
+pub fn subquery_alias(plan: &LogicalPlan, alias: &str) -> Result<LogicalPlan> {
+ subquery_alias_owned(plan.clone(), alias)
+}
+
+pub fn subquery_alias_owned(plan: LogicalPlan, alias: &str) ->
Result<LogicalPlan> {
+ let schema: Schema = plan.schema().as_ref().clone().into();
+ let schema = DFSchemaRef::new(DFSchema::try_from_qualified_schema(alias,
&schema)?);
+ Ok(LogicalPlan::SubqueryAlias(SubqueryAlias {
input: Arc::new(plan),
- alias,
- schema: Arc::new(schema),
- })
+ alias: alias.to_string(),
+ schema,
+ }))
}
Review Comment:
Could we move this logic into `SubqueryAlias::try_new` instead?
--
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]