andygrove commented on code in PR #3209:
URL: https://github.com/apache/arrow-datafusion/pull/3209#discussion_r950492656


##########
datafusion/sql/src/planner.rs:
##########
@@ -336,14 +346,37 @@ 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.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))
+                            }),
+                    )

Review Comment:
   We can use the pattern matching to extract the vector of columns by using 
`Some(c)` instead of `Some(_)` and then we can reference that instead of using 
`columns.unwrap()`.
   
   ```suggestion
               Some(c) => {
                   let mut new_builder = LogicalPlanBuilder::from(plan.clone());
                   new_builder = new_builder
                       
.project(plan.schema().fields().iter().zip(c.into_iter()).map(
                           |(field, ident)| 
col(field.name()).alias(&normalize_ident(ident)),
                       ))
   ```



-- 
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]

Reply via email to