You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/04/11 16:06:29 UTC

[arrow-rs] branch master updated: Add offsets accessors to variable length arrays (#3879) (#4048)

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

tustvold 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 ee4003328 Add offsets accessors to variable length arrays (#3879) (#4048)
ee4003328 is described below

commit ee4003328d6615e011303ba57c24264a3f454e12
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Tue Apr 11 17:06:22 2023 +0100

    Add offsets accessors to variable length arrays (#3879) (#4048)
    
    * Add offsets accessors to variable length arrays (#3879)
    
    * Review feedback
---
 arrow-array/src/array/byte_array.rs | 18 ++++++++++++++++++
 arrow-array/src/array/list_array.rs | 12 +++++++++++-
 arrow-array/src/array/map_array.rs  | 13 +++++++++++--
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/arrow-array/src/array/byte_array.rs b/arrow-array/src/array/byte_array.rs
index 34e7d79ab..f0e43e694 100644
--- a/arrow-array/src/array/byte_array.rs
+++ b/arrow-array/src/array/byte_array.rs
@@ -67,6 +67,24 @@ impl<T: ByteArrayType> GenericByteArray<T> {
         offsets[i + 1] - offsets[i]
     }
 
+    /// Returns a reference to the offsets of this array
+    ///
+    /// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
+    /// allowing for zero-copy cloning
+    #[inline]
+    pub fn offsets(&self) -> &OffsetBuffer<T::Offset> {
+        &self.value_offsets
+    }
+
+    /// Returns the values of this array
+    ///
+    /// Unlike [`Self::value_data`] this returns the [`Buffer`]
+    /// allowing for zero-copy cloning
+    #[inline]
+    pub fn values(&self) -> &Buffer {
+        &self.value_data
+    }
+
     /// Returns the raw value data
     pub fn value_data(&self) -> &[u8] {
         self.value_data.as_slice()
diff --git a/arrow-array/src/array/list_array.rs b/arrow-array/src/array/list_array.rs
index fb94fe12c..f47ea8069 100644
--- a/arrow-array/src/array/list_array.rs
+++ b/arrow-array/src/array/list_array.rs
@@ -78,7 +78,17 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
         DataType::List
     };
 
-    /// Returns a reference to the values of this list.
+    /// Returns a reference to the offsets of this list
+    ///
+    /// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
+    /// allowing for zero-copy cloning
+    #[inline]
+    pub fn offsets(&self) -> &OffsetBuffer<OffsetSize> {
+        &self.value_offsets
+    }
+
+    /// Returns a reference to the values of this list
+    #[inline]
     pub fn values(&self) -> &ArrayRef {
         &self.values
     }
diff --git a/arrow-array/src/array/map_array.rs b/arrow-array/src/array/map_array.rs
index 22ebbe533..1629532b8 100644
--- a/arrow-array/src/array/map_array.rs
+++ b/arrow-array/src/array/map_array.rs
@@ -42,12 +42,21 @@ pub struct MapArray {
 }
 
 impl MapArray {
-    /// Returns a reference to the keys of this map.
+    /// Returns a reference to the offsets of this map
+    ///
+    /// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
+    /// allowing for zero-copy cloning
+    #[inline]
+    pub fn offsets(&self) -> &OffsetBuffer<i32> {
+        &self.value_offsets
+    }
+
+    /// Returns a reference to the keys of this map
     pub fn keys(&self) -> &ArrayRef {
         &self.keys
     }
 
-    /// Returns a reference to the values of this map.
+    /// Returns a reference to the values of this map
     pub fn values(&self) -> &ArrayRef {
         &self.values
     }