pub struct PrimitiveData { /* private fields */ }Expand description
A primitive array that stores native types in a contiguous buffer of memory, along with an optional validity child.
This mirrors the Apache Arrow Primitive layout and can be converted into and out of one without allocations or copies.
The underlying buffer must be natively aligned to the primitive type they are representing.
Values are stored in their native representation with proper alignment. Null values still occupy space in the buffer but are marked invalid in the validity mask.
§Examples
use vortex_array::arrays::PrimitiveArray;
use vortex_array::{LEGACY_SESSION, VortexSessionExecute};
// Create from iterator using FromIterator impl
let array: PrimitiveArray = [1i32, 2, 3, 4, 5].into_iter().collect();
// Slice the array
let sliced = array.slice(1..3)?;
// Access individual values
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let value = sliced.execute_scalar(0, &mut ctx).unwrap();
assert_eq!(value, 2i32.into());
Implementations§
Source§impl PrimitiveData
impl PrimitiveData
Sourcepub fn as_slice<T>(&self) -> &[T]where
T: NativePType,
pub fn as_slice<T>(&self) -> &[T]where
T: NativePType,
Return a slice of the array’s buffer.
NOTE: these values may be nonsense if the validity buffer indicates that the value is null.
§Panic
This operation will panic if the array is not backed by host memory.
Source§impl PrimitiveData
impl PrimitiveData
Sourcepub unsafe fn new_unchecked_from_handle(
handle: BufferHandle,
ptype: PType,
_validity: Validity,
) -> PrimitiveData
pub unsafe fn new_unchecked_from_handle( handle: BufferHandle, ptype: PType, _validity: Validity, ) -> PrimitiveData
Create a new array from a buffer handle.
§Safety
Should ensure that the provided BufferHandle points at sufficiently large region of aligned
memory to hold the ptype values.
Sourcepub fn new<T>(buffer: impl Into<Buffer<T>>, validity: Validity) -> PrimitiveDatawhere
T: NativePType,
pub fn new<T>(buffer: impl Into<Buffer<T>>, validity: Validity) -> PrimitiveDatawhere
T: NativePType,
Creates a new PrimitiveArray.
§Panics
Panics if the provided components do not satisfy the invariants documented
in PrimitiveArray::new_unchecked.
Sourcepub fn try_new<T>(
buffer: Buffer<T>,
validity: Validity,
) -> Result<PrimitiveData, VortexError>where
T: NativePType,
pub fn try_new<T>(
buffer: Buffer<T>,
validity: Validity,
) -> Result<PrimitiveData, VortexError>where
T: NativePType,
Constructs a new PrimitiveArray.
See PrimitiveArray::new_unchecked for more information.
§Errors
Returns an error if the provided components do not satisfy the invariants documented in
PrimitiveArray::new_unchecked.
Sourcepub unsafe fn new_unchecked<T>(
buffer: Buffer<T>,
_validity: Validity,
) -> PrimitiveDatawhere
T: NativePType,
pub unsafe fn new_unchecked<T>(
buffer: Buffer<T>,
_validity: Validity,
) -> PrimitiveDatawhere
T: NativePType,
Creates a new PrimitiveArray without validation from these components:
bufferis a typed buffer containing the primitive values.validityholds the null values.
§Safety
The caller must ensure all of the following invariants are satisfied:
§Validity Requirements
- If
validityisValidity::Array, its length must exactly equalbuffer.len().
Sourcepub fn validate<T>(
buffer: &Buffer<T>,
validity: &Validity,
) -> Result<(), VortexError>where
T: NativePType,
pub fn validate<T>(
buffer: &Buffer<T>,
validity: &Validity,
) -> Result<(), VortexError>where
T: NativePType,
Validates the components that would be used to create a PrimitiveArray.
This function checks all the invariants required by PrimitiveArray::new_unchecked.
pub fn empty<T>(nullability: Nullability) -> PrimitiveDatawhere
T: NativePType,
Source§impl PrimitiveData
impl PrimitiveData
pub fn len(&self) -> usize
pub fn ptype(&self) -> PType
Sourcepub fn buffer_handle(&self) -> &BufferHandle
pub fn buffer_handle(&self) -> &BufferHandle
Get access to the buffer handle backing the array.
pub fn from_buffer_handle( handle: BufferHandle, ptype: PType, _validity: Validity, ) -> PrimitiveData
pub fn from_byte_buffer( buffer: Buffer<u8>, ptype: PType, validity: Validity, ) -> PrimitiveData
Sourcepub fn from_values_byte_buffer(
valid_elems_buffer: Buffer<u8>,
ptype: PType,
validity: Validity,
n_rows: usize,
) -> PrimitiveData
pub fn from_values_byte_buffer( valid_elems_buffer: Buffer<u8>, ptype: PType, validity: Validity, n_rows: usize, ) -> PrimitiveData
Create a PrimitiveArray from a byte buffer containing only the valid elements.
Sourcepub fn to_buffer<T>(&self) -> Buffer<T>where
T: NativePType,
pub fn to_buffer<T>(&self) -> Buffer<T>where
T: NativePType,
Get a buffer in host memory holding all the values.
NOTE: some values may be nonsense if the validity buffer indicates that the value is null.
Sourcepub fn into_buffer<T>(self) -> Buffer<T>where
T: NativePType,
pub fn into_buffer<T>(self) -> Buffer<T>where
T: NativePType,
Consume the array and get a host Buffer containing the data values.
Sourcepub fn into_buffer_mut<T>(self) -> BufferMut<T>where
T: NativePType,
pub fn into_buffer_mut<T>(self) -> BufferMut<T>where
T: NativePType,
Extract a mutable buffer from the PrimitiveData. Attempts to do this with zero-copy if the buffer is uniquely owned, otherwise will make a copy.
Sourcepub fn try_into_buffer_mut<T>(self) -> Result<BufferMut<T>, Buffer<T>>where
T: NativePType,
pub fn try_into_buffer_mut<T>(self) -> Result<BufferMut<T>, Buffer<T>>where
T: NativePType,
Try to extract a mutable buffer from the PrimitiveData with zero copy.
Trait Implementations§
Source§impl ArrayEq for PrimitiveData
impl ArrayEq for PrimitiveData
Source§impl ArrayHash for PrimitiveData
impl ArrayHash for PrimitiveData
Source§impl Clone for PrimitiveData
impl Clone for PrimitiveData
Source§fn clone(&self) -> PrimitiveData
fn clone(&self) -> PrimitiveData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PrimitiveData
impl Debug for PrimitiveData
Auto Trait Implementations§
impl !Freeze for PrimitiveData
impl !RefUnwindSafe for PrimitiveData
impl Send for PrimitiveData
impl Sync for PrimitiveData
impl Unpin for PrimitiveData
impl UnsafeUnpin for PrimitiveData
impl !UnwindSafe for PrimitiveData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynArrayDataEq for Twhere
T: ArrayEq + 'static,
impl<T> DynArrayDataEq for Twhere
T: ArrayEq + 'static,
Source§impl<T> DynArrayDataHash for T
impl<T> DynArrayDataHash for T
fn dyn_array_hash(&self, state: &mut dyn Hasher, precision: Precision)
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.