pub struct DataChunk { /* private fields */ }Expand description
A non-owning wrapper around a duckdb_data_chunk.
This wrapper does not destroy the chunk on drop — DuckDB owns the
chunk and manages its lifetime. DataChunk simply provides ergonomic
methods for accessing vectors and metadata within callback functions.
Implementations§
Source§impl DataChunk
impl DataChunk
Sourcepub const unsafe fn from_raw(raw: duckdb_data_chunk) -> Self
pub const unsafe fn from_raw(raw: duckdb_data_chunk) -> Self
Wraps a raw duckdb_data_chunk handle.
§Safety
raw must be a valid duckdb_data_chunk obtained from a DuckDB
callback (e.g., a scan callback’s output parameter or an aggregate
update callback’s input chunk). The chunk must remain valid for
the lifetime of this wrapper.
Sourcepub unsafe fn set_size(&self, size: usize)
pub unsafe fn set_size(&self, size: usize)
Sets the number of rows in this data chunk.
Call this in scan callbacks after writing output rows. Set to 0 to
signal end of stream.
§Safety
size must not exceed the chunk’s capacity (typically 2048).
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Returns the number of columns in this data chunk.
Sourcepub unsafe fn vector(&self, col_idx: usize) -> duckdb_vector
pub unsafe fn vector(&self, col_idx: usize) -> duckdb_vector
Returns the raw duckdb_vector handle for the given column index.
§Safety
col_idx must be less than column_count.
Sourcepub unsafe fn writer(&self, col_idx: usize) -> VectorWriter
pub unsafe fn writer(&self, col_idx: usize) -> VectorWriter
Creates a VectorWriter for the given column index.
§Safety
col_idxmust be less thancolumn_count.- The chunk must be a writable output chunk (not a read-only input chunk).
Sourcepub unsafe fn reader(&self, col_idx: usize) -> VectorReader
pub unsafe fn reader(&self, col_idx: usize) -> VectorReader
Creates a VectorReader for the given column index.
The reader’s row count is set to this chunk’s current size.
§Safety
col_idx must be less than column_count.
Sourcepub unsafe fn struct_reader(
&self,
col_idx: usize,
field_count: usize,
) -> StructReader
pub unsafe fn struct_reader( &self, col_idx: usize, field_count: usize, ) -> StructReader
Creates a StructReader for a STRUCT column at the given index.
This is a convenience method that combines vector with
StructReader::new.
§Safety
col_idxmust be less thancolumn_count.- The column at
col_idxmust have a STRUCT type withfield_countfields.
Sourcepub unsafe fn struct_field_reader(
&self,
col_idx: usize,
field_idx: usize,
) -> VectorReader
pub unsafe fn struct_field_reader( &self, col_idx: usize, field_idx: usize, ) -> VectorReader
Creates a VectorReader for a field of a STRUCT column.
Convenience for accessing a specific field in a STRUCT input column.
§Safety
col_idxmust be less thancolumn_count.- The column at
col_idxmust have a STRUCT type. field_idxmust be a valid field index within the STRUCT.
Sourcepub unsafe fn struct_writer(
&self,
col_idx: usize,
field_count: usize,
) -> StructWriter
pub unsafe fn struct_writer( &self, col_idx: usize, field_count: usize, ) -> StructWriter
Creates a StructWriter for a STRUCT column at the given index.
This is a convenience method that combines vector with
StructWriter::new.
§Safety
col_idxmust be less thancolumn_count.- The column at
col_idxmust have a STRUCT type withfield_countfields. - The chunk must be a writable output chunk.
Sourcepub const unsafe fn into_chunk_writer(self) -> ChunkWriter
pub const unsafe fn into_chunk_writer(self) -> ChunkWriter
Creates a ChunkWriter for this output data chunk.
The ChunkWriter tracks rows via next_row()
and automatically calls set_size on drop.
§Safety
This chunk must be a valid, writable output chunk from a table function scan callback.
Sourcepub const fn as_raw(&self) -> duckdb_data_chunk
pub const fn as_raw(&self) -> duckdb_data_chunk
Returns the raw duckdb_data_chunk handle.