You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by su...@apache.org on 2022/03/11 18:31:12 UTC

[arrow-rs] branch master updated: Add value_unchecked() for FixedSizeBinaryArray (#1420)

This is an automated email from the ASF dual-hosted git repository.

sunchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 7393560  Add value_unchecked() for FixedSizeBinaryArray (#1420)
7393560 is described below

commit 73935606a9ab436ccb6b71cf5c60901384f66e29
Author: jakevin <30...@users.noreply.github.com>
AuthorDate: Sat Mar 12 02:31:08 2022 +0800

    Add value_unchecked() for FixedSizeBinaryArray (#1420)
---
 arrow/src/array/array_binary.rs | 12 ++++++++++++
 arrow/src/array/equal/mod.rs    | 13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs
index e35133e..88ff3bf 100644
--- a/arrow/src/array/array_binary.rs
+++ b/arrow/src/array/array_binary.rs
@@ -473,6 +473,18 @@ impl FixedSizeBinaryArray {
         }
     }
 
+    /// Returns the element at index `i` as a byte slice.
+    /// # Safety
+    /// Caller is responsible for ensuring that the index is within the bounds of the array
+    pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] {
+        let offset = i.checked_add(self.data.offset()).unwrap();
+        let pos = self.value_offset_at(offset);
+        std::slice::from_raw_parts(
+            self.value_data.as_ptr().offset(pos as isize),
+            (self.value_offset_at(offset + 1) - pos) as usize,
+        )
+    }
+
     /// Returns the offset for the element at index `i`.
     ///
     /// Note this doesn't do any bound checking, for performance reason.
diff --git a/arrow/src/array/equal/mod.rs b/arrow/src/array/equal/mod.rs
index 7bd0b70..4f27786 100644
--- a/arrow/src/array/equal/mod.rs
+++ b/arrow/src/array/equal/mod.rs
@@ -601,6 +601,19 @@ mod tests {
     }
 
     #[test]
+    fn test_fixed_size_binary_array() {
+        let a_input_arg = vec![vec![1, 2], vec![3, 4], vec![5, 6]];
+        let a = FixedSizeBinaryArray::try_from_iter(a_input_arg.into_iter()).unwrap();
+        let a = a.data();
+
+        let b_input_arg = vec![vec![1, 2], vec![3, 4], vec![5, 6]];
+        let b = FixedSizeBinaryArray::try_from_iter(b_input_arg.into_iter()).unwrap();
+        let b = b.data();
+
+        test_equal(a, b, true);
+    }
+
+    #[test]
     fn test_string_offset() {
         let a = StringArray::from(vec![Some("a"), None, Some("b")]);
         let a = a.data();