You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/19 19:00:00 UTC
[GitHub] [arrow-datafusion] DaltonModlin commented on a diff in pull request #3209: feat(planner): Add support for inline column alias
DaltonModlin commented on code in PR #3209:
URL: https://github.com/apache/arrow-datafusion/pull/3209#discussion_r950487937
##########
datafusion/sql/src/planner.rs:
##########
@@ -336,14 +346,40 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
Some(cte_name.clone()),
&mut ctes.clone(),
outer_query_schema,
+ columns,
)?;
ctes.insert(cte_name, logical_plan);
}
}
let plan = self.set_expr_to_plan(*set_expr, alias, ctes, outer_query_schema)?;
let plan = self.order_by(plan, query.order_by)?;
- self.limit(plan, query.offset, query.limit)
+ let plan = self.limit(plan, query.offset, query.limit);
+ match columns {
+ Some(_) => {
+ let mut new_builder =
+ LogicalPlanBuilder::from(plan.as_ref().unwrap().clone());
+ new_builder = new_builder
+ .project(
+ plan.as_ref()
+ .unwrap()
+ .schema()
+ .fields()
+ .iter()
+ .zip(columns.unwrap().into_iter())
+ .map(|(field, ident)| {
+ col(field.name()).alias(&normalize_ident(ident))
+ }),
+ )
+ .map_err(|e| {
+ context!("Failed to apply alias to inline projection.\n", e)
+ })?;
+ new_builder.build()
+ }
+ None => {
+ plan
+ }
+ }
Review Comment:
Oh that's a really nice change, using the ? operator to create a value rather than a result on return! Thanks for the note, I'll make the update.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org