#[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.
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 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 AsRef<Table> for PyRecordBatch
impl AsRef<Table> for PyRecordBatch
Source§impl ColumnSelection for Table
Available on crate features views and select only.
impl ColumnSelection for Table
views and select only.Source§type ColumnView = ArrayV
type ColumnView = ArrayV
Source§type ColumnOwned = FieldArray
type ColumnOwned = FieldArray
.get() e.g. FieldArray for Table, Arc