Skip to content

Commit

Permalink
Add offsets accessors to variable length arrays (apache#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Apr 11, 2023
1 parent ff670c5 commit 9ecabfd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 12 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,18 @@ impl<T: ByteArrayType> GenericByteArray<T> {
offsets[i + 1] - offsets[i]
}

/// Returns a reference to the offsets of this array
#[inline]
pub fn offsets(&self) -> &OffsetBuffer<T::Offset> {
&self.value_offsets
}

/// Returns the values of this array
#[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
9 changes: 8 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,14 @@ 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
#[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
10 changes: 8 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,18 @@ pub struct MapArray {
}

impl MapArray {
/// Returns a reference to the keys of this map.
/// Returns a reference to the offsets of this map
#[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 9ecabfd

Please sign in to comment.