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

[GitHub] [arrow-rs] tustvold opened a new pull request, #3933: Add typed buffers to UnionArray (#3880)

tustvold opened a new pull request, #3933:
URL: https://github.com/apache/arrow-rs/pull/3933

   # 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.
   -->
   
   Part of #3880
   
   # 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?
   
   This changes the return type of UnionArray::value_offset to be correct
   <!--
   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] viirya commented on pull request #3933: Add typed buffers to UnionArray (#3880)

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #3933:
URL: https://github.com/apache/arrow-rs/pull/3933#issuecomment-1488893588

   I'll review this today.


-- 
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] viirya commented on a diff in pull request #3933: Add typed buffers to UnionArray (#3880)

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


##########
arrow-array/src/array/union_array.rs:
##########
@@ -241,21 +243,29 @@ impl UnionArray {
     ///
     /// Panics if `index` is greater than the length of the array.
     pub fn type_id(&self, index: usize) -> i8 {
-        assert!(index < self.len());
-        self.data().buffers()[0].as_slice()[self.offset() + index] as i8
+        self.type_ids[index]
+    }
+
+    /// Returns the `type_ids` for this array

Review Comment:
   nit to match `offsets` :
   ```suggestion
       /// Returns the `type_ids` buffer for this array
   ```



-- 
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 #3933: Add typed buffers to UnionArray (#3880)

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


-- 
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 #3933: Add typed buffers to UnionArray (#3880)

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


##########
arrow-array/src/array/union_array.rs:
##########
@@ -241,21 +243,29 @@ impl UnionArray {
     ///
     /// Panics if `index` is greater than the length of the array.
     pub fn type_id(&self, index: usize) -> i8 {
-        assert!(index < self.len());
-        self.data().buffers()[0].as_slice()[self.offset() + index] as i8
+        self.type_ids[index]
+    }
+
+    /// Returns the `type_ids` for this array
+    pub fn type_ids(&self) -> &ScalarBuffer<i8> {
+        &self.type_ids
+    }
+
+    /// Returns the `offsets` buffer if this is a dense array
+    pub fn offsets(&self) -> Option<&ScalarBuffer<i32>> {
+        self.offsets.as_ref()
     }
 
     /// Returns the offset into the underlying values array for the array slot at `index`.
     ///
     /// # Panics
     ///
     /// Panics if `index` is greater than the length of the array.
-    pub fn value_offset(&self, index: usize) -> i32 {
+    pub fn value_offset(&self, index: usize) -> usize {
         assert!(index < self.len());
-        if self.is_dense() {
-            self.data().buffers()[1].typed_data::<i32>()[self.offset() + index]
-        } else {
-            (self.offset() + index) as i32

Review Comment:
   This can potentially overflow, so I opted to change value_offset to return usize as this is not only more correct, but is what most call-sites want anyway



-- 
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] viirya commented on a diff in pull request #3933: Add typed buffers to UnionArray (#3880)

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


##########
arrow/src/ffi.rs:
##########
@@ -1138,37 +1139,34 @@ mod tests {
         let expected_type_ids = vec![0_i8, 0, 1, 0];
 
         // Check type ids
-        assert_eq!(
-            Buffer::from_slice_ref(&expected_type_ids),
-            *array.data().buffers()[0]
-        );
+        assert_eq!(*array.type_ids(), expected_type_ids);
         for (i, id) in expected_type_ids.iter().enumerate() {
             assert_eq!(id, &array.type_id(i));
         }
 
         // Check offsets, sparse union should only have a single buffer, i.e. no offsets
-        assert_eq!(array.data().buffers().len(), 1);

Review Comment:
   👍 



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