pub struct DataChunk {
pub fields: Vec<Arc<dyn Array>>,
pub field_types: Vec<PhysicalTypeID>,
pub size: usize,
pub field_names: Vec<String>,
pub sel_vector: Option<SelectionVector>,
}Expand description
A contiguous batch of columnar data — the fundamental unit of data exchange between physical operators.
Each DataChunk holds zero or more Arrow ArrayRef columns of equal length.
Operators consume input chunks and produce output chunks, forming a pipeline.
§Selection vectors
When sel_vector is set, only the rows indicated by the selection are “active”.
Call active_rows() or iter_rows() to respect the selection; do not iterate
0..size directly.
§Example
let chunk = DataChunk::new(fields, field_types).with_names(names);
for row in chunk.iter_rows() {
let val = chunk.get_value(0, row); // column 0, current row
}Fields§
§fields: Vec<Arc<dyn Array>>§field_types: Vec<PhysicalTypeID>§size: usize§field_names: Vec<String>§sel_vector: Option<SelectionVector>Optional selection vector for zero-copy filtering.
When set, only the rows at sel_vector.indices[0..sel_vector.size]
are considered active. Operators should iterate using the sel_vector
rather than size for correct results.
Implementations§
Source§impl DataChunk
impl DataChunk
Sourcepub fn new(
fields: Vec<Arc<dyn Array>>,
field_types: Vec<PhysicalTypeID>,
) -> DataChunk
pub fn new( fields: Vec<Arc<dyn Array>>, field_types: Vec<PhysicalTypeID>, ) -> DataChunk
Create a new DataChunk from Arrow arrays and their physical types.
The chunk size is set to the length of the first field. All fields
must have the same length.
Sourcepub fn from_legacy(legacy_fields: Vec<LegacyValueVector>) -> DataChunk
pub fn from_legacy(legacy_fields: Vec<LegacyValueVector>) -> DataChunk
Construct a DataChunk from legacy vectors (for backward-compatibility in benchmarks)
Sourcepub fn with_names(self, names: Vec<String>) -> DataChunk
pub fn with_names(self, names: Vec<String>) -> DataChunk
Attach column names to this chunk (builder pattern).
Sourcepub fn with_sel(self, sel: SelectionVector) -> DataChunk
pub fn with_sel(self, sel: SelectionVector) -> DataChunk
Attach a selection vector to this chunk.
Sourcepub fn field(&self, idx: usize) -> &Arc<dyn Array> ⓘ
pub fn field(&self, idx: usize) -> &Arc<dyn Array> ⓘ
Return a reference to the Arrow array at the given column index.
Sourcepub fn num_fields(&self) -> usize
pub fn num_fields(&self) -> usize
Return the number of columns in this chunk.
Sourcepub fn resize(&mut self, new_size: usize)
pub fn resize(&mut self, new_size: usize)
Resize the chunk (and all its fields) to the given number of rows.
Sourcepub fn active_rows(&self) -> usize
pub fn active_rows(&self) -> usize
Return the number of active rows, taking the selection vector into account.
Sourcepub fn iter_rows(&self) -> RowIter<'_> ⓘ
pub fn iter_rows(&self) -> RowIter<'_> ⓘ
Iterate over active row indices. When a selection vector is present, yields the selected indices. Otherwise, yields 0..size.
Sourcepub fn materialize(&mut self)
pub fn materialize(&mut self)
Materialize the selection vector into physical data. After calling this, sel_vector is None and only the selected rows remain in the data buffers. This is a no-op if sel_vector is already None.
Sourcepub fn is_null(&self, field_idx: usize, row_idx: usize) -> bool
pub fn is_null(&self, field_idx: usize, row_idx: usize) -> bool
Return true if the value at (field_idx, row_idx) is null.
Sourcepub fn get_i64(&self, field_idx: usize, row_idx: usize) -> Option<i64>
pub fn get_i64(&self, field_idx: usize, row_idx: usize) -> Option<i64>
Read an i64 value from column field_idx at row_idx, or None if null.
Returns None if the column is not physically an Int64 array (e.g. a
UInt64 column) — callers reading UInt64 columns must use get_u64.
Sourcepub fn get_u64(&self, field_idx: usize, row_idx: usize) -> Option<u64>
pub fn get_u64(&self, field_idx: usize, row_idx: usize) -> Option<u64>
Read a u64 value from column field_idx at row_idx, or None if null.
Sourcepub fn get_i32(&self, field_idx: usize, row_idx: usize) -> Option<i32>
pub fn get_i32(&self, field_idx: usize, row_idx: usize) -> Option<i32>
Read an i32 value from column field_idx at row_idx, or None if null.
Sourcepub fn get_f64(&self, field_idx: usize, row_idx: usize) -> Option<f64>
pub fn get_f64(&self, field_idx: usize, row_idx: usize) -> Option<f64>
Read an f64 value from column field_idx at row_idx, or None if null.
Sourcepub fn get_f32(&self, field_idx: usize, row_idx: usize) -> Option<f32>
pub fn get_f32(&self, field_idx: usize, row_idx: usize) -> Option<f32>
Read an f32 value from column field_idx at row_idx, or None if null.
Sourcepub fn get_bool(&self, field_idx: usize, row_idx: usize) -> Option<bool>
pub fn get_bool(&self, field_idx: usize, row_idx: usize) -> Option<bool>
Read a bool value from column field_idx at row_idx, or None if null.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DataChunk
impl !UnwindSafe for DataChunk
impl Freeze for DataChunk
impl Send for DataChunk
impl Sync for DataChunk
impl Unpin for DataChunk
impl UnsafeUnpin for DataChunk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more