crepererum commented on code in PR #3148:
URL: https://github.com/apache/arrow-rs/pull/3148#discussion_r1028219176


##########
arrow-schema/src/field.rs:
##########
@@ -68,9 +68,33 @@ impl Ord for Field {
     fn cmp(&self, other: &Self) -> Ordering {
         self.name
             .cmp(other.name())
-            .then(self.data_type.cmp(other.data_type()))
-            .then(self.nullable.cmp(&other.nullable))
-            .then(self.metadata.cmp(&other.metadata))
+            .then_with(|| self.data_type.cmp(other.data_type()))
+            .then_with(|| self.nullable.cmp(&other.nullable))
+            .then_with(|| {
+                // ensure deterministic key order
+                let mut keys: Vec<&String> =
+                    
self.metadata.keys().chain(other.metadata.keys()).collect();
+                keys.sort();
+                for k in keys {
+                    match (self.metadata.get(k), other.metadata.get(k)) {
+                        (None, None) => {}
+                        (Some(_), None) => {
+                            return Ordering::Greater;

Review Comment:
   Technically this doesn't matter since `HashMap`s aren't ordered by default, 
so "who goes first" is implementation-defined by arrow, but I'll add a test.



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