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 10:09:35 UTC

[GitHub] [arrow-rs] Weijun-H opened a new pull request, #4042: feat: DataType::contains support nested type

Weijun-H opened a new pull request, #4042:
URL: https://github.com/apache/arrow-rs/pull/4042

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #4029
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163063937


##########
arrow-schema/src/field.rs:
##########
@@ -524,7 +524,14 @@ impl Field {
         // make sure self.metadata is a superset of other.metadata
         && other.metadata.iter().all(|(k, v1)| {
             self.metadata.get(k).map(|v2| v1 == v2).unwrap_or_default()
-        })
+        }) {
+            true
+        } else if self.data_type().is_nested() {
+            // if self is a nested type, check if self contains other
+            self.data_type().contains(other)
+        } else {
+            false
+        }

Review Comment:
   I think this will now return true if a nested field contains, but even if properties like `self.name` are not equal?
   
   Perhaps we could just change `self.data_type == other.data_type` to be `self.data_type.contains(&other.data_type)`



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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1161634647


##########
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 think this should call through to Field::contains, which in turn should call through to DataType



##########
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),
+            DataType::Struct(fields) => {
+                fields.iter().any(|field| field.data_type().contains(other))

Review Comment:
   This should call through to Fields::contains



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


[GitHub] [arrow-rs] tustvold merged pull request #4042: feat: DataType::contains support nested type

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042


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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1161806455


##########
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:
   No, adding fields is not supported. I agree the name is perhaps unhelpful. It is basically used for testing if the layout of a given set of arrays is compatible



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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163635719


##########
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, other) {
+            (DataType::List(f1), DataType::List(f2))
+            | (DataType::LargeList(f1), DataType::LargeList(f2)) => f1.contains(f2),
+            (DataType::FixedSizeList(f1, s1), DataType::FixedSizeList(f2, s2)) => {
+                s1 == s2 && f1.contains(f2)
+            }
+            (DataType::Map(f1, s1), DataType::Map(f2, s2)) => s1 == s2 && f1.contains(f2),
+            (DataType::Struct(f1), DataType::Struct(f2)) => f1.contains(f2),
+            (DataType::Union(f1, s1), DataType::Union(f2, s2)) => {
+                s1 == s2 && f1.iter().all(|f1| f2.iter().any(|f2| f1.1.contains(f2.1)))

Review Comment:
   I _think_ this should also check the type IDs 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: github-unsubscribe@arrow.apache.org

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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163157393


##########
arrow-schema/src/datatype.rs:
##########
@@ -498,6 +498,27 @@ 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: &Field) -> bool {

Review Comment:
   ```
   match (self, other) {
       (DataType::Struct(f1), DataType::Struct(f2)) => f1.contains(f2),
       ....
   }
   
   ```



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


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

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163156541


##########
arrow-schema/src/datatype.rs:
##########
@@ -498,6 +498,27 @@ 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: &Field) -> bool {

Review Comment:
   If we take a `DataType`, how could we call `Field::contains` following?



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


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

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
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


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

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163064906


##########
arrow-schema/src/datatype.rs:
##########
@@ -498,6 +498,27 @@ 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: &Field) -> bool {

Review Comment:
   ```suggestion
       pub fn contains(&self, other: &DataType) -> bool {
   ```
   I would expect this to take a `DataType`



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


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

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4042:
URL: https://github.com/apache/arrow-rs/pull/4042#discussion_r1163156541


##########
arrow-schema/src/datatype.rs:
##########
@@ -498,6 +498,27 @@ 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: &Field) -> bool {

Review Comment:
   If we take a `DataType`, how could we call `Field::contains`?



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