Skip to content

Commit

Permalink
Add offsets accessors to variable length arrays (#3879) (#4048)
Browse files Browse the repository at this point in the history
* Add offsets accessors to variable length arrays (#3879)

* Review feedback
  • Loading branch information
tustvold authored Apr 11, 2023
1 parent 6b17775 commit ee40033
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
18 changes: 18 additions & 0 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ee40033

Please sign in to comment.