You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Weijun-H (via GitHub)" <gi...@apache.org> on 2023/04/10 13:49:02 UTC

[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4042: feat: DataType::contains support nested type

Weijun-H commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1161735624


##########
arrow-schema/src/datatype.rs:
##########
@@ -498,6 +498,29 @@ impl DataType {
                 }
             }
     }
+
+    /// Check to see if `self` is a superset of `other`
+    ///
+    /// If DataType is a nested type, then it will check to see if the nested type is a superset of the other nested type
+    /// else it will check to see if the DataType is equal to the other DataType
+    pub fn contains(&self, other: &DataType) -> bool {
+        match self {
+            DataType::List(field)
+            | DataType::LargeList(field)
+            | DataType::Map(field, _)
+            | DataType::FixedSizeList(field, _) => field.data_type().contains(other),

Review Comment:
   I would like to further clarify the definition of 'contain' through testing. Are the following tests accurate for this purpose?
   ``` rust
       #[test]
       fn test_contains_nested_field() {
           let child_field1 = Field::new("child1", DataType::Float16, false);
           let child_field2 = Field::new("child2", DataType::Float16, false);
   
           let field1 = Field::new(
               "field1",
               DataType::Struct(vec![child_field1.clone()].into()),
               true,
           );
           let field2 = Field::new(
               "field1",
               DataType::Struct(vec![child_field1, child_field2].into()),
               true,
           );
   
           assert!(field2.contains(&field1));
           assert!(!field1.contains(&field2));
       }
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org