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.
Examples found in repository?
149fn example_2_export_table_stream(py: Python<'_>) -> PyResult<()> {
150 println!("Example 2: Export MinArrow table -> PyArrow via __arrow_c_stream__");
151 println!("------------------------------------------------------------------");
152
153 let mut ids = IntegerArray::<i32>::default();
154 ids.push(1);
155 ids.push(2);
156 ids.push(3);
157
158 let mut scores = FloatArray::<f64>::default();
159 scores.push(9.5);
160 scores.push(8.3);
161 scores.push(7.1);
162
163 let table = Table::new(
164 "results".to_string(),
165 Some(vec![
166 FieldArray::new(
167 Field::new("id", ArrowType::Int32, false, None),
168 Array::from_int32(ids),
169 ),
170 FieldArray::new(
171 Field::new("score", ArrowType::Float64, false, None),
172 Array::from_float64(scores),
173 ),
174 ]),
175 );
176 println!(" Created MinArrow table: 3 rows x 2 columns (id, score)");
177
178 // Export as a stream capsule and extract the raw pointer for PyArrow
179 let stream_capsule = to_py::table_to_stream_capsule(&table, py)?;
180 let stream_ptr = unsafe {
181 pyo3::ffi::PyCapsule_GetPointer(
182 stream_capsule.as_ptr(),
183 c"arrow_array_stream".as_ptr(),
184 )
185 } as usize;
186
187 let pyarrow = py.import("pyarrow")?;
188 let reader = pyarrow
189 .getattr("RecordBatchReader")?
190 .call_method1("_import_from_c", (stream_ptr,))?;
191 let pa_table = reader.call_method0("read_all")?;
192
193 let num_rows: usize = pa_table.getattr("num_rows")?.extract()?;
194 let schema_repr: String = pa_table.getattr("schema")?.call_method0("__repr__")?.extract()?;
195 println!(" PyArrow received: {} rows", num_rows);
196 println!(" Schema: {}", schema_repr.lines().next().unwrap_or(""));
197 println!(" Done.\n");
198 Ok(())
199}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 tz(&self, tz: &str) -> Result<FieldArray, MinarrowError>
pub fn tz(&self, tz: &str) -> Result<FieldArray, MinarrowError>
Returns a new FieldArray with updated timezone metadata.
The underlying timestamp data (always UTC) remains unchanged. Only the timezone metadata in the Field’s ArrowType is updated for interpretation/display purposes.
§Arguments
tz- Timezone string in Arrow format (IANA like “America/New_York” or offset like “+05:00”)
§Errors
Returns an error if the array is not a Timestamp type.
Sourcepub fn utc(&self) -> Result<FieldArray, MinarrowError>
pub fn utc(&self) -> Result<FieldArray, MinarrowError>
Returns a new FieldArray with timezone metadata set to “UTC”.
The underlying timestamp data (always UTC) remains unchanged. Only the timezone metadata in the Field’s ArrowType is updated.
§Errors
Returns an error if the array is not a Timestamp type.
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 · 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 PyArray
impl From<FieldArray> for PyArray
Source§fn from(field_array: FieldArray) -> Self
fn from(field_array: FieldArray) -> Self
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<PyArray> for FieldArray
impl From<PyArray> for FieldArray
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.