Skip to content
26 changes: 26 additions & 0 deletions arrow-row/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ use arrow_array::types::{Int16Type, Int32Type, Int64Type};

mod fixed;
mod list;
pub mod radix;
mod run;
mod variable;

Expand Down Expand Up @@ -1451,6 +1452,31 @@ impl<'a> Row<'a> {
pub fn data(&self) -> &'a [u8] {
self.data
}

/// The byte at `offset`, or 0 if `offset` is past the end of the row.
#[inline]
pub fn byte_from(&self, offset: usize) -> u8 {
if offset < self.data.len() {
// SAFETY: bounds checked above
unsafe { *self.data.get_unchecked(offset) }
} else {
0
}
}

/// The row's bytes starting at `offset`, or an empty slice if
/// `offset` exceeds the row length.
///
/// Useful for comparing rows that share a known prefix (e.g.,
/// after radix sort has already discriminated on earlier bytes).
pub fn data_from(&self, offset: usize) -> &'a [u8] {
if offset <= self.data.len() {
// SAFETY: bounds checked above
unsafe { self.data.get_unchecked(offset..) }
} else {
&[]
}
}
}

// Manually derive these as don't wish to include `fields`
Expand Down
Loading
Loading