pub struct VectorWriter { /* private fields */ }Expand description
A typed writer for a DuckDB output vector in a finalize callback.
§Example
use quack_rs::vector::VectorWriter;
use libduckdb_sys::duckdb_vector;
// Inside finalize:
// let mut writer = unsafe { VectorWriter::new(result_vector) };
// for row in 0..count {
// if let Some(val) = compute_result(row) {
// unsafe { writer.write_i64(row, val) };
// } else {
// unsafe { writer.set_null(row) };
// }
// }Implementations§
Source§impl VectorWriter
impl VectorWriter
Sourcepub unsafe fn new(vector: duckdb_vector) -> Self
pub unsafe fn new(vector: duckdb_vector) -> Self
Creates a new VectorWriter for the given result vector.
§Safety
vector must be a valid DuckDB output vector obtained in a finalize
callback. The vector must not be destroyed while this writer is live.
Sourcepub unsafe fn from_vector(vector: duckdb_vector) -> Self
pub unsafe fn from_vector(vector: duckdb_vector) -> Self
Creates a VectorWriter directly from a raw duckdb_vector handle.
Use this when you need to write into a child vector (e.g., a STRUCT field
or LIST element vector) obtained from
StructVector::get_child or
ListVector::get_child.
§Safety
vector must be a valid, writable duckdb_vector. The vector must not be
destroyed while this writer is live.
Sourcepub const unsafe fn write_i8(&mut self, idx: usize, value: i8)
pub const unsafe fn write_i8(&mut self, idx: usize, value: i8)
Writes an i8 (TINYINT) value at row idx.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TINYINTtype.
Sourcepub unsafe fn write_bool(&mut self, idx: usize, value: bool)
pub unsafe fn write_bool(&mut self, idx: usize, value: bool)
Writes a bool (BOOLEAN) value at row idx.
Booleans are stored as a single byte: 1 for true, 0 for false.
§Safety
idxmust be within the vector’s capacity.- The vector must have
BOOLEANtype.
Sourcepub const unsafe fn write_i128(&mut self, idx: usize, value: i128)
pub const unsafe fn write_i128(&mut self, idx: usize, value: i128)
Writes an i128 (HUGEINT) value at row idx.
DuckDB stores HUGEINT as { lower: u64, upper: i64 } in little-endian
layout, totaling 16 bytes per value.
§Safety
idxmust be within the vector’s capacity.- The vector must have
HUGEINTtype.
Sourcepub unsafe fn write_varchar(&mut self, idx: usize, value: &str)
pub unsafe fn write_varchar(&mut self, idx: usize, value: &str)
Writes a VARCHAR string value at row idx.
This uses duckdb_vector_assign_string_element_len which handles both
the inline (≤12 bytes) and pointer (>12 bytes) storage formats
automatically. DuckDB manages the memory for the string data.
§Note on very long strings
If value.len() exceeds idx_t::MAX (2^64 − 1 on 64-bit platforms),
the length is silently clamped to idx_t::MAX. In practice, this limit
is unreachable on any current hardware (≈18 exabytes), so no explicit
error path is provided.
§Safety
idxmust be within the vector’s capacity.- The vector must have
VARCHARtype.
Sourcepub const unsafe fn write_date(&mut self, idx: usize, days_since_epoch: i32)
pub const unsafe fn write_date(&mut self, idx: usize, days_since_epoch: i32)
Sourcepub const unsafe fn write_timestamp(
&mut self,
idx: usize,
micros_since_epoch: i64,
)
pub const unsafe fn write_timestamp( &mut self, idx: usize, micros_since_epoch: i64, )
Sourcepub const unsafe fn write_time(
&mut self,
idx: usize,
micros_since_midnight: i64,
)
pub const unsafe fn write_time( &mut self, idx: usize, micros_since_midnight: i64, )
Sourcepub const unsafe fn write_interval(&mut self, idx: usize, value: DuckInterval)
pub const unsafe fn write_interval(&mut self, idx: usize, value: DuckInterval)
Writes an INTERVAL value at row idx.
DuckDB stores INTERVAL as { months: i32, days: i32, micros: i64 } in a
16-byte layout. This method writes all three components at the correct offsets.
§Safety
idxmust be within the vector’s capacity.- The vector must have
INTERVALtype.
Sourcepub unsafe fn write_blob(&mut self, idx: usize, value: &[u8])
pub unsafe fn write_blob(&mut self, idx: usize, value: &[u8])
Writes a BLOB (binary) value at row idx.
This uses the same underlying storage as VARCHAR — DuckDB stores BLOBs
using duckdb_vector_assign_string_element_len, which copies the data.
§Safety
idxmust be within the vector’s capacity.- The vector must have
BLOBtype.
Sourcepub const unsafe fn write_uuid(&mut self, idx: usize, value: i128)
pub const unsafe fn write_uuid(&mut self, idx: usize, value: i128)
Writes a UUID value at row idx.
DuckDB stores UUID as a HUGEINT (128-bit integer). This is a semantic
alias for write_i128.
§Safety
idxmust be within the vector’s capacity.- The vector must have
UUIDtype.
Sourcepub unsafe fn write_str(&mut self, idx: usize, value: &str)
pub unsafe fn write_str(&mut self, idx: usize, value: &str)
Writes a VARCHAR string value at row idx.
This is an alias for write_varchar provided
for discoverability — extension authors often look for write_str first.
§Safety
idxmust be within the vector’s capacity.- The vector must have
VARCHARtype.
Sourcepub unsafe fn set_null(&mut self, idx: usize)
pub unsafe fn set_null(&mut self, idx: usize)
Marks row idx as NULL in the output vector.
§Pitfall L4: ensure_validity_writable
This method calls duckdb_vector_ensure_validity_writable before
duckdb_vector_get_validity, which is required before writing any NULL
flags. Forgetting this call returns an uninitialized pointer.
§Safety
idxmust be within the vector’s capacity.
Sourcepub const fn as_raw(&self) -> duckdb_vector
pub const fn as_raw(&self) -> duckdb_vector
Returns the underlying raw vector handle.