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


##########
datafusion/sql/src/planner.rs:
##########
@@ -189,8 +189,27 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 query,
                 with_options,
                 ..
-            } if columns.is_empty() && with_options.is_empty() => {
-                let plan = self.query_to_plan(*query, &mut HashMap::new())?;
+            } if with_options.is_empty() => {
+                let mut plan = self.query_to_plan(*query, &mut 
HashMap::new())?;
+
+                if !columns.is_empty() {
+                    plan = LogicalPlanBuilder::from(plan.clone())
+                        .project(
+                            
plan.schema().fields().iter().zip(columns.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()

Review Comment:
   This is fine and no need to change this but just an FYI really, you can 
avoid having multiple `map_err` like this:
   
   ```suggestion
                           .and_then(|builder| builder.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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to