Skip to main content

Table

Struct Table 

Source
#[repr(C, align(64))]
pub struct Table { pub cols: Vec<FieldArray>, pub n_rows: usize, pub name: String, }
Expand description

§Table

§Description

  • Standard columnar table with named columns (FieldArray), a fixed number of rows, and an optional logical table name.
  • All columns are required to be equal length and have consistent schema.
  • Supports zero-copy slicing, efficient iteration, and bulk operations.
  • Equivalent to the RecordBatch in Apache Arrow.

§Structure

  • cols: A vector of FieldArray, each representing a column with metadata and data.
  • n_rows: The logical number of rows (guaranteed equal for all columns).
  • name: Optional logical name or alias for this table instance.

§Usage

  • Use Table as a general-purpose, in-memory columnar data container.
  • Good for analytics, and transformation pipelines.
  • For batched/partitioned tables, see SuperTable or windowed/chunked abstractions.
  • Cast into Polars dataframe via .to_polars() or Apache Arrow via .to_apache_arrow()
  • FFI-compatible

§Notes

  • Table instances are typically lightweight to clone and pass by value.
  • For mutation, construct a new table or replace individual columns as needed.
  • There is an alias RecordBatch under crate::aliases::RecordBatch

§Example

use minarrow::{fa_i32, fa_str32, Print, Table};

let col1 = fa_i32!("numbers", 1, 2, 3);
let col2 = fa_str32!("letters", "x", "y", "z");

let mut tbl = Table::new("Demo".into(), vec![col1, col2].into());
tbl.print();

Fields§

§cols: Vec<FieldArray>

FieldArrays representing named columns.

§n_rows: usize

Number of rows in the table.

§name: String

Table name

Implementations§

Source§

impl Table

Source

pub fn new(name: String, cols: Option<Vec<FieldArray>>) -> Table

Constructs a new Table with a specified name and optional columns. If cols is provided, the number of rows will be inferred from the first column.

Examples found in repository?
examples/pycapsule_exchange.rs (lines 163-175)
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}
Source

pub fn new_empty() -> Table

Constructs a new, empty Table with a globally unique name.

Source

pub fn add_col(&mut self, field_array: FieldArray)

Adds a column with a name.

Source

pub fn schema(&self) -> Vec<Arc<Field>>

Builds a schema via the underlying field arrays

Source

pub fn n_cols(&self) -> usize

Returns the number of columns.

Source

pub fn n_rows(&self) -> usize

Returns the number of rows.

Source

pub fn is_empty(&self) -> bool

Returns true if the table is empty (no columns or no rows).

Source

pub fn col_names(&self) -> Vec<&str>

Returns the list of column names.

Source

pub fn rename_columns( &mut self, mapping: &[(&str, &str)], ) -> Result<(), MinarrowError>

Rename columns in place. Each pair is (old_name, new_name).

Returns an error if any old name is not found. This is metadata-only - array data is not touched.

Source

pub fn col_name_index(&self, name: &str) -> Option<usize>

Returns the index of a column by name.

Source

pub fn col_numeric(&self, name: &str) -> Result<NumericArrayV, MinarrowError>

Resolve a named column to a NumericArrayV.

Source

pub fn col_text(&self, name: &str) -> Result<TextArrayV, MinarrowError>

Resolve a named column to a TextArrayV.

Source

pub fn col_bitmask(&self, name: &str) -> Result<BitmaskV, MinarrowError>

Resolve a named column to a BitmaskV.

Source

pub fn remove_col(&mut self, name: &str) -> bool

Removes a column by name.

Source

pub fn remove_col_at(&mut self, idx: usize) -> bool

Removes a column by index.

Source

pub fn clear(&mut self)

Clears all columns and resets row count.

Source

pub fn has_col(&self, name: &str) -> bool

Checks if a column with the given name exists.

Source

pub fn cols(&self) -> &[FieldArray]

Returns all columns as a slice.

Source

pub fn cols_mut(&mut self) -> &mut [FieldArray]

Returns mutable reference to all columns.

Source

pub fn iter(&self) -> Iter<'_, FieldArray>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, FieldArray>

Source

pub fn set_name(&mut self, name: impl Into<String>)

Source

pub fn len(&self) -> usize

Source

pub fn slice_clone(&self, offset: usize, len: usize) -> Table

Returns a new owned Table containing rows [offset, offset+len).

All columns are deeply copied, but only for the affected row(s).

Source

pub fn slice(&self, offset: usize, len: usize) -> TableV

Returns a zero-copy view over rows [offset, offset+len). This view borrows from the parent table and does not copy data.

Source

pub fn map_col<T, F>(&self, col_name: &str, func: F) -> Option<T>
where F: FnOnce(&FieldArray) -> T,

Maps a function over a single column by name, returning the result. Returns None if the column doesn’t exist.

Source

pub fn map_cols_by_name<T, F>(&self, col_names: &[&str], func: F) -> Vec<T>
where F: FnMut(&FieldArray) -> T,

Maps a function over multiple columns by name, returning a Vec of results. Warns if any requested columns are missing.

Source

pub fn map_cols_by_index<T, F>(&self, indices: &[usize], func: F) -> Vec<T>
where F: FnMut(&FieldArray) -> T,

Maps a function over multiple columns by index, returning a Vec of results. Warns if any requested indices are out of bounds.

Source

pub fn map_all_cols<T, F>(&self, func: F) -> Vec<T>
where F: FnMut(&FieldArray) -> T,

Maps a function over all columns, returning a Vec of results.

Source

pub fn apply_cols<E>( &self, f: impl FnMut(&FieldArray) -> Result<FieldArray, E>, ) -> Result<Table, E>

Apply a transformation to each column, producing a new table.

The closure receives each FieldArray and returns a transformed FieldArray. To pass a column through unchanged, clone it. The closure can dispatch on Array variant to handle numeric, text, temporal, and boolean columns differently.

Source

pub fn insert_rows( &mut self, index: usize, other: &Table, ) -> Result<(), MinarrowError>

Inserts rows from another table at the specified index.

This is an O(n) operation where n is the number of rows after the insertion point.

§Arguments
  • index - Position before which to insert (0 = prepend, n_rows = append)
  • other - Table to insert
§Requirements
  • Both tables must have the same number of columns
  • Column names, types, and nullability must match in order
  • index must be <= self.n_rows()
§Errors
  • IndexError if index > n_rows
  • IncompatibleTypeError if column schemas don’t match
Source

pub fn split(self, index: usize) -> Result<SuperTable, MinarrowError>

Splits the Table at the specified row index, consuming self and returning a SuperTable with two Table batches.

Splits the underlying buffers, allocating new storage for the second half.

Trait Implementations§

Source§

impl AsRef<Table> for PyRecordBatch

Source§

fn as_ref(&self) -> &Table

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ColumnSelection for Table

Available on crate features views and select only.
Source§

type View = TableV

The view type returned by multi-field selection e.g. TableV
Source§

type ColumnView = ArrayV

A single column view by index e.g. ArrayV
Source§

type ColumnOwned = FieldArray

An owned single field by name via .get() e.g. FieldArray for Table, Arc for Cube
Source§

fn c<S>(&self, selection: S) -> TableV
where S: FieldSelector,

Select fields/columns by name, index, or range Read more
Source§

fn get(&self, field: &str) -> Option<FieldArray>

Get a single field by name, returning an owned value.
Source§

fn col_ix(&self, idx: usize) -> Option<ArrayV>

Get a single column view by index
Source§

fn col_vec(&self) -> Vec<ArrayV>

Get all columns as views
Source§

fn get_cols(&self) -> Vec<Arc<Field>>

Get the fields for field resolution
Source§

fn col(&self, name: &str) -> Self::View

Alias for c - select column by name
Source§

impl Concatenate for Table

Source§

fn concat(self, other: Table) -> Result<Table, MinarrowError>

Concatenates two tables vertically (row-wise).

§Requirements
  • Both tables must have the same number of columns
  • Column names, types, and nullability must match in order
§Returns

A new Table with rows from self followed by rows from other

§Errors
  • IncompatibleTypeError if column schemas don’t match
Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Table

Source§

fn default() -> Table

Returns the “default value” for a type. Read more
Source§

impl Display for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<PyRecordBatch> for Table

Source§

fn from(value: PyRecordBatch) -> Self

Converts to this type from the input type.
Source§

impl From<Table> for PyRecordBatch

Source§

fn from(table: Table) -> Self

Converts to this type from the input type.
Source§

impl From<TableV> for Table

TableV -> Table conversion. Respects active column selection.

Source§

fn from(view: TableV) -> Table

Converts to this type from the input type.
Source§

impl FromIterator<Table> for SuperTable

Source§

fn from_iter<T>(iter: T) -> SuperTable
where T: IntoIterator<Item = Table>,

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a Table

Source§

type Item = &'a FieldArray

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, FieldArray>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Table as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Table

Source§

type Item = &'a mut FieldArray

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, FieldArray>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a mut Table as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Table

Source§

type Item = FieldArray

The type of the elements being iterated over.
Source§

type IntoIter = <Vec<FieldArray> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Table as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Table

Source§

fn eq(&self, other: &Table) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RowSelection for Table

Available on crate features views and select only.
Source§

type View = TableV

The view type returned by selection operations
Source§

fn r<S>(&self, selection: S) -> TableV
where S: DataSelector,

Select rows by index or range Read more
Source§

fn get_row_count(&self) -> usize

Get the count for data resolution
Source§

impl Shape for Table

Source§

fn shape(&self) -> ShapeDim

Returns arbitrary Shape dimension for any data shape
Source§

fn shape_1d(&self) -> usize

Returns the first dimension shape Read more
Source§

fn shape_2d(&self) -> (usize, usize)

Returns the first and second dimension shapes Read more
Source§

fn shape_3d(&self) -> (usize, usize, usize)

Returns the first, second and third dimension shapes Read more
Source§

fn shape_4d(&self) -> (usize, usize, usize, usize)

Returns the first, second, third and fourth dimension shapes Read more
Source§

impl StructuralPartialEq for Table

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl UnwindSafe for Table

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CustomValue for T
where T: Any + Send + Sync + Clone + PartialEq + Debug,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcasts the type as Any
Source§

fn deep_clone(&self) -> Arc<dyn CustomValue>

Returns a deep clone of the object. Read more
Source§

fn eq_box(&self, other: &(dyn CustomValue + 'static)) -> bool

Performs semantic equality on the boxed object. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Print for T
where T: Display,

Source§

fn print(&self)
where Self: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,