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:27:23 UTC

[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3209: Add support for inline column alias in CREATE VIEW

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


##########
datafusion/sql/src/planner.rs:
##########
@@ -336,14 +346,29 @@ 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(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)),
+                    ))
+                    .map_err(|e| {
+                        context!("Failed to apply alias to inline projection.\n", e)
+                    })?;
+                new_builder.build()
+            }

Review Comment:
   We can lose the (mutable) variable here as well:
   
   ```suggestion
               Some(c) => LogicalPlanBuilder::from(plan.clone())
                   .project(plan.schema().fields().iter().zip(c.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)
                   })?
                   .build(),
   ```



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