pub struct FieldArray {
pub field: Arc<Field>,
pub array: Array,
pub null_count: usize,
}Expand description
§FieldArray
Named and typed data column with associated array values.
§Role
- Combines a
Fieldwith an immutableArrayinstance. FieldArrayintegrates naturally into aTable, where immutability enforces row-length guarantees. It can also serve as a self-documenting array and is required when sendingMinarrowdata over FFI toApache Arrow. In such cases, it’s worth ensuring the correct logicalDatetimeArrow type is built when constructing theField, as this determines theArrowtype on the receiving side.
§Examples
use minarrow::{Array, Field, FieldArray, MaskedArray};
use minarrow::ffi::arrow_dtype::ArrowType;
use minarrow::structs::variants::integer::IntegerArray;
// Build a typed array
let mut ints = IntegerArray::<i32>::default();
ints.push(1);
ints.push(2);
let arr = Array::from_int32(ints);
// Construct with a Field and Array
let field = Field::new("id", ArrowType::Int32, false, None);
let fa = FieldArray::new(field, arr);
assert_eq!(fa.field.name, "id");
assert_eq!(fa.arrow_type(), ArrowType::Int32);
assert_eq!(fa.len(), 2);
// Take an owned slice [offset..offset+len)
let sub = fa.slice_clone(0, 1);
assert_eq!(sub.len(), 1);The fa_* macros are a concise construction shorthand:
use minarrow::{fa_i32, fa_i32_opt, fa_str32};
use minarrow::ffi::arrow_dtype::ArrowType;
// From literal values - type and nullability inferred
let fa = fa_i32!("id", 1, 2);
assert_eq!(fa.field.name, "id");
assert_eq!(fa.arrow_type(), ArrowType::Int32);
assert_eq!(fa.len(), 2);
// Nullable variant with Option values
let fa = fa_i32_opt!("score", Some(10i32), None::<i32>, Some(30));
assert_eq!(fa.len(), 3);
assert!(fa.field.nullable);
assert_eq!(fa.null_count(), 1);
// String columns
let names = fa_str32!("name", "alice", "bob");
assert_eq!(names.field.name, "name");
assert_eq!(names.len(), 2);Fields§
§field: Arc<Field>Array metadata
array: ArrayThe array’s inner payload is wrapped in Arc for immutability so it can safely share across threads. When part of a Table (or higher-dimensional structure), immutability also upholds shape constraints.
null_count: usizeNull count for the immutable array to support skipping null-mask
operations when it’s 0, and/or related strategies.
Implementations§
Source§impl FieldArray
impl FieldArray
Sourcepub fn new(field: Field, array: Array) -> FieldArray
pub fn new(field: Field, array: Array) -> FieldArray
Constructs a new FieldArray from an existing Field and Array.
Sourcepub fn new_arc(field: Arc<Field>, array: Array) -> FieldArray
pub fn new_arc(field: Arc<Field>, array: Array) -> FieldArray
Constructs a new FieldArray from an existing Arc<Field> and Array.
Sourcepub fn from_arr<N, A>(name: N, arr: A) -> FieldArray
pub fn from_arr<N, A>(name: N, arr: A) -> FieldArray
Constructs a new FieldArray from a name and any supported typed array,
automatically wrapping as Array and inferring type and nullability.
Sourcepub fn from_parts<T>(
field_name: T,
dtype: ArrowType,
nullable: Option<bool>,
metadata: Option<BTreeMap<String, String>>,
array: Array,
) -> FieldArray
pub fn from_parts<T>( field_name: T, dtype: ArrowType, nullable: Option<bool>, metadata: Option<BTreeMap<String, String>>, array: Array, ) -> FieldArray
Constructs a new FieldArray from raw field components and an Array.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn arrow_type(&self) -> ArrowType
Sourcepub fn view(
&self,
offset: usize,
len: usize,
) -> ((&Array, usize, usize), &Field)
pub fn view( &self, offset: usize, len: usize, ) -> ((&Array, usize, usize), &Field)
Returns a zero-copy view (FieldArraySlice) into the window [offset, offset+len).
The returned object holds references into the original FieldArray.
The (&Array, Offset, WindowLength), &Field) FieldArraySlice pattern here
is a once-off we avoid recommending.
Sourcepub fn slice_clone(&self, offset: usize, len: usize) -> FieldArray
pub fn slice_clone(&self, offset: usize, len: usize) -> FieldArray
Returns a new owned FieldArray with array sliced [offset, offset+len).
Sourcepub fn refresh_null_count(&mut self)
pub fn refresh_null_count(&mut self)
Updates the cached null_count from the underlying array. Should be called after any mutation of the array that could change null count.
Sourcepub fn null_count(&self) -> usize
pub fn null_count(&self) -> usize
Returns the cached null count. This is kept in sync with the underlying array via refresh_null_count().
Sourcepub fn concat_field_array(&mut self, other: &FieldArray)
pub fn concat_field_array(&mut self, other: &FieldArray)
Concatenates another FieldArray’s data into this one using copy-on-write semantics. If this FieldArray’s array has Arc reference count > 1, the data is cloned first. Both FieldArrays must have compatible types. Updates the cached null_count.
Sourcepub fn concat_range(
&mut self,
other: &FieldArray,
offset: usize,
len: usize,
) -> Result<(), MinarrowError>
pub fn concat_range( &mut self, other: &FieldArray, offset: usize, len: usize, ) -> Result<(), MinarrowError>
Appends rows [offset..offset+len) from another FieldArray into self.
Extends data directly from the source’s backing buffer.
Sourcepub fn with_array_mut<F, R>(&mut self, f: F) -> R
pub fn with_array_mut<F, R>(&mut self, f: F) -> R
Provides mutable access to the underlying array with automatic null_count refresh. Uses copy-on-write semantics - clones array data if Arc reference count > 1. Use this for operations that may change the null count.
Trait Implementations§
Source§impl Clone for FieldArray
impl Clone for FieldArray
Source§fn clone(&self) -> FieldArray
fn clone(&self) -> FieldArray
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Concatenate for FieldArray
impl Concatenate for FieldArray
Source§fn concat(self, other: FieldArray) -> Result<FieldArray, MinarrowError>
fn concat(self, other: FieldArray) -> Result<FieldArray, MinarrowError>
Source§impl Debug for FieldArray
impl Debug for FieldArray
Source§impl Display for FieldArray
impl Display for FieldArray
Source§impl From<&FieldArray> for ArrayV
&FieldArray -> ArrayView
impl From<&FieldArray> for ArrayV
&FieldArray -> ArrayView
Arc bumps inner array with offset 0, length self.len().
Source§fn from(field_array: &FieldArray) -> ArrayV
fn from(field_array: &FieldArray) -> ArrayV
Source§impl From<FieldArray> for SuperArray
impl From<FieldArray> for SuperArray
Source§fn from(fa: FieldArray) -> SuperArray
fn from(fa: FieldArray) -> SuperArray
Source§impl From<FieldArray> for NumericArrayV
impl From<FieldArray> for NumericArrayV
Source§fn from(field_array: FieldArray) -> NumericArrayV
fn from(field_array: FieldArray) -> NumericArrayV
Source§impl From<FieldArray> for ArrayV
FieldArray -> ArrayView
impl From<FieldArray> for ArrayV
FieldArray -> ArrayView
Takes self.array then offset 0, length self.len())
Source§fn from(field_array: FieldArray) -> ArrayV
fn from(field_array: FieldArray) -> ArrayV
Source§impl FromIterator<FieldArray> for SuperArray
impl FromIterator<FieldArray> for SuperArray
Source§fn from_iter<T>(iter: T) -> SuperArraywhere
T: IntoIterator<Item = FieldArray>,
fn from_iter<T>(iter: T) -> SuperArraywhere
T: IntoIterator<Item = FieldArray>,
Source§impl PartialEq for FieldArray
impl PartialEq for FieldArray
Source§impl RowSelection for FieldArray
Available on crate features select and views only.
impl RowSelection for FieldArray
select and views only.