alamb commented on code in PR #10695:
URL: https://github.com/apache/arrow-rs/pull/10695#discussion_r3789217137


##########
arrow-schema/src/metadata.rs:
##########
@@ -146,6 +146,19 @@ impl Metadata {
     pub fn values(&self) -> impl Iterator<Item = &String> {
         self.iter().map(|(_, value)| value)
     }
+
+    /// Retains only the entries for which `f(&key, &mut value)` returns 
`true`.
+    ///
+    /// Entries for which `f` returns `false` are removed. Retained entries
+    /// remain in their original (sorted) order.
+    ///
+    /// Clones the underlying map if (and only if) it is shared.
+    pub fn retain<F>(&mut self, eq: F)
+    where
+        F: FnMut(&String, &mut String) -> bool,
+    {
+        Arc::make_mut(self.0.get_or_insert_default()).retain(eq);

Review Comment:
   Does calling get_or_insert_default mean this method would turn a metadata 
that had a None inner map into aSome(empty map)?
   
   I think it would make more sense to do nothing if `self.0` is None 



##########
arrow-schema/src/metadata.rs:
##########
@@ -445,6 +458,35 @@ mod tests {
         assert_eq!(format!("{metadata:?}"), r#"{"a": "1", "b": "2"}"#);
         assert_eq!(format!("{:?}", Metadata::new()), "{}");
     }
+    #[test]
+    fn test_retain() {
+        let mut metadata =
+            Metadata::from([("a", "1"), ("b", "2"), ("c", "3"), ("d", "4"), 
("e", "5")]);
+
+        metadata.retain(|k, _| -> bool { k >= &String::from("c") });
+
+        let result_map = Metadata::from([("c", "3"), ("d", "4"), ("e", "5")]);
+        assert_eq!(metadata, result_map)
+    }
+
+    #[test]

Review Comment:
   Can you please add a test that shows what happens when retain is called on a 
empty Metadata (`None`)? It should I think still be `None`



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