#[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
RecordBatchin Apache Arrow.
§Structure
cols: A vector ofFieldArray, 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
Tableas a general-purpose, in-memory columnar data container. - Good for analytics, and transformation pipelines.
- For batched/partitioned tables, see
SuperTableor 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
RecordBatchunder 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: usizeNumber of rows in the table.
name: StringTable name
Implementations§
Source§impl Table
impl Table
Sourcepub fn new(name: String, cols: Option<Vec<FieldArray>>) -> Table
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.
Sourcepub fn add_col(&mut self, field_array: FieldArray)
pub fn add_col(&mut self, field_array: FieldArray)
Adds a column with a name.
Sourcepub fn rename_columns(
&mut self,
mapping: &[(&str, &str)],
) -> Result<(), MinarrowError>
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.
Sourcepub fn col_name_index(&self, name: &str) -> Option<usize>
pub fn col_name_index(&self, name: &str) -> Option<usize>
Returns the index of a column by name.
Sourcepub fn col_numeric(&self, name: &str) -> Result<NumericArrayV, MinarrowError>
pub fn col_numeric(&self, name: &str) -> Result<NumericArrayV, MinarrowError>
Resolve a named column to a NumericArrayV.
Sourcepub fn col_text(&self, name: &str) -> Result<TextArrayV, MinarrowError>
pub fn col_text(&self, name: &str) -> Result<TextArrayV, MinarrowError>
Resolve a named column to a TextArrayV.
Sourcepub fn col_bitmask(&self, name: &str) -> Result<BitmaskV, MinarrowError>
pub fn col_bitmask(&self, name: &str) -> Result<BitmaskV, MinarrowError>
Resolve a named column to a BitmaskV.
Sourcepub fn remove_col(&mut self, name: &str) -> bool
pub fn remove_col(&mut self, name: &str) -> bool
Removes a column by name.
Sourcepub fn remove_col_at(&mut self, idx: usize) -> bool
pub fn remove_col_at(&mut self, idx: usize) -> bool
Removes a column by index.
Sourcepub fn cols(&self) -> &[FieldArray]
pub fn cols(&self) -> &[FieldArray]
Returns all columns as a slice.
Sourcepub fn cols_mut(&mut self) -> &mut [FieldArray]
pub fn cols_mut(&mut self) -> &mut [FieldArray]
Returns mutable reference to all columns.
pub fn iter(&self) -> Iter<'_, FieldArray>
pub fn iter_mut(&mut self) -> IterMut<'_, FieldArray>
pub fn set_name(&mut self, name: impl Into<String>)
pub fn len(&self) -> usize
Sourcepub fn slice_clone(&self, offset: usize, len: usize) -> Table
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).
Sourcepub fn slice(&self, offset: usize, len: usize) -> TableV
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.
Sourcepub fn map_col<T, F>(&self, col_name: &str, func: F) -> Option<T>where
F: FnOnce(&FieldArray) -> T,
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.
Sourcepub fn map_cols_by_name<T, F>(&self, col_names: &[&str], func: F) -> Vec<T>where
F: FnMut(&FieldArray) -> T,
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.
Sourcepub fn map_cols_by_index<T, F>(&self, indices: &[usize], func: F) -> Vec<T>where
F: FnMut(&FieldArray) -> T,
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.
Sourcepub fn map_all_cols<T, F>(&self, func: F) -> Vec<T>where
F: FnMut(&FieldArray) -> T,
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.
Sourcepub fn apply_cols<E>(
&self,
f: impl FnMut(&FieldArray) -> Result<FieldArray, E>,
) -> Result<Table, E>
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.
Sourcepub fn insert_rows(
&mut self,
index: usize,
other: &Table,
) -> Result<(), MinarrowError>
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
indexmust be <=self.n_rows()
§Errors
IndexErrorif index > n_rowsIncompatibleTypeErrorif column schemas don’t match
Sourcepub fn split(self, index: usize) -> Result<SuperTable, MinarrowError>
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 ColumnSelection for Table
Available on crate features select and views only.
impl ColumnSelection for Table
select and views only.Source§type ColumnView = ArrayV
type ColumnView = ArrayV
Source§type ColumnOwned = FieldArray
type ColumnOwned = FieldArray
.get() e.g. FieldArray for Table, Arc