Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offsets accessors to variable length arrays (#3879) #4048

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might help to note in the docstrings:

  1. How this is different than value_offsets (other than the signature)
  2. Which is preferred (it sounds from this PR's description that offsets is preferred, but that is not obvious from the code as it is written)

The same applies to values and value_data

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