alamb commented on code in PR #5607:
URL: https://github.com/apache/arrow-datafusion/pull/5607#discussion_r1140042872


##########
datafusion/optimizer/src/eliminate_duplicated_expr.rs:
##########
@@ -41,15 +42,28 @@ impl OptimizerRule for EliminateDuplicatedExpr {
     ) -> Result<Option<LogicalPlan>> {
         match plan {
             LogicalPlan::Sort(sort) => {
+                let normalized_sort_keys = sort
+                    .expr
+                    .iter()
+                    .map(|e| match e {
+                        Expr::Sort(ExprSort { expr, .. }) => {
+                            Expr::Sort(ExprSort::new(expr.clone(), true, 
false))
+                        }
+                        _ => e.clone(),
+                    })
+                    .collect::<Vec<_>>();
+
                 // dedup sort.expr and keep order
                 let mut dedup_expr = Vec::new();
                 let mut dedup_set = HashSet::new();
-                for expr in &sort.expr {
-                    if !dedup_set.contains(expr) {
-                        dedup_expr.push(expr);
-                        dedup_set.insert(expr.clone());
-                    }
-                }
+                sort.expr.iter().zip(normalized_sort_keys.iter()).for_each(
+                    |(expr, normalized_expr)| {

Review Comment:
   I think I missed the case that the expr/normalized expr match 👍 



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