mingmwang commented on code in PR #4643:
URL: https://github.com/apache/arrow-datafusion/pull/4643#discussion_r1050523235


##########
datafusion/expr/src/utils.rs:
##########
@@ -984,4 +1120,48 @@ mod tests {
         assert_eq!(expected, result);
         Ok(())
     }
+
+    #[test]
+    fn avoid_generate_duplicate_sort_keys() -> Result<()> {
+        let asc_or_desc = [true, false];
+        let nulls_first_or_last = [true, false];
+        let partition_by = &[col("age"), col("name"), col("created_at")];
+        for asc_ in asc_or_desc {
+            for nulls_first_ in nulls_first_or_last {
+                let order_by = &[
+                    Expr::Sort {
+                        expr: Box::new(col("age")),
+                        asc: asc_,
+                        nulls_first: nulls_first_,
+                    },
+                    Expr::Sort {
+                        expr: Box::new(col("name")),
+                        asc: asc_,
+                        nulls_first: nulls_first_,
+                    },
+                ];
+
+                let expected = vec![
+                    Expr::Sort {
+                        expr: Box::new(col("age")),
+                        asc: asc_,
+                        nulls_first: nulls_first_,
+                    },
+                    Expr::Sort {
+                        expr: Box::new(col("name")),
+                        asc: asc_,
+                        nulls_first: nulls_first_,
+                    },
+                    Expr::Sort {
+                        expr: Box::new(col("created_at")),
+                        asc: true,
+                        nulls_first: false,
+                    },
+                ];
+                let result = generate_sort_key(partition_by, order_by)?;
+                assert_eq!(expected, result);

Review Comment:
   yes, this PR will do additional dedup to avoid generate duplicate sort keys.



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