andygrove commented on code in PR #3209:
URL: https://github.com/apache/arrow-datafusion/pull/3209#discussion_r950482255
##########
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:
We can remove some of the `unwrap` calls here by adding `?` onto the
`self.limit` call:
```suggestion
let plan = self.limit(plan, query.offset, query.limit)?;
match columns {
Some(_) => {
let mut new_builder =
LogicalPlanBuilder::from(plan.clone());
new_builder = new_builder
.project(
plan
.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 => {
Ok(plan)
}
}
```
--
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]