comphead commented on code in PR #6566:
URL: https://github.com/apache/arrow-datafusion/pull/6566#discussion_r1237115792


##########
datafusion/sql/src/select.rs:
##########
@@ -194,7 +198,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 .iter()
                 .map(|expr| rebase_expr(expr, &window_func_exprs, &plan))
                 .collect::<Result<Vec<Expr>>>()?;
-
+            if select.into.is_some() {
+                for expr in select_exprs_post_aggr.iter_mut() {
+                    if let Expr::Column(_) = expr.clone() {
+                        *expr = expr.clone().alias(physical_name(expr)?);
+                    }
+                }
+            }

Review Comment:
   @berkaysynnada thanks for checking that.
   
   I was also working on that.
   Changing `display_name` was the one I started with but in this case other 
scenarios will fail. When window plan created the DFS schema check name 
uniqueness from `display_name` not considering aliases. So this query will fail
   ```
   SELECT
     first_value(c9) OVER (PARTITION BY c2 ORDER BY c9) first_c9,
     first_value(c9) OVER (PARTITION BY c2 ORDER BY c9 DESC) first_c9_desc
   FROM aggregate_test_100
   ```
   
   I'm still thinking how to overcome that without breaking changes



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