alamb commented on code in PR #20658:
URL: https://github.com/apache/datafusion/pull/20658#discussion_r2912686805


##########
datafusion/sql/src/unparser/rewrite.rs:
##########
@@ -223,7 +223,15 @@ pub(super) fn 
rewrite_plan_for_sort_on_non_projected_fields(
 
     let mut collects = p.expr.clone();
     for sort in &sort.expr {
-        collects.push(sort.expr.clone());
+        // Strip aliases from sort expressions so the comparison matches
+        // the inner Projection's raw expressions. The optimizer may add
+        // sort expressions to the inner Projection without aliases, while
+        // the Sort node's expressions carry aliases from the original plan.
+        let mut expr = sort.expr.clone();

Review Comment:
   I think this is the same as 
https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.unalias_nested



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to