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, bits: u128)
pub const unsafe fn write_uuid(&mut self, idx: usize, bits: u128)
Writes a UUID value at row idx.
Writes bits — the UUID’s textual 128 bits, as every Rust Uuid
type holds them — at row idx.
A UUID column is physically a HUGEINT, but DuckDB stores it with
the top bit flipped so that signed integer ordering matches UUID string
ordering. This applies that flip, so the value you pass is the value the
column renders. Use write_i128 to write the raw
storage instead, and uuid_to_storage
to convert between the two.
§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 const unsafe fn write_u128(&mut self, idx: usize, value: u128)
pub const unsafe fn write_u128(&mut self, idx: usize, value: u128)
Writes a u128 (UHUGEINT) value at row idx.
DuckDB stores UHUGEINT as { lower: u64, upper: u64 } in little-endian
layout, totalling 16 bytes per value.
§Safety
idxmust be within the vector’s capacity.- The vector must have
UHUGEINTtype.
Sourcepub const unsafe fn write_timestamp_tz(
&mut self,
idx: usize,
micros_since_epoch: i64,
)
pub const unsafe fn write_timestamp_tz( &mut self, idx: usize, micros_since_epoch: i64, )
Writes a TIMESTAMP WITH TIME ZONE value at row idx, as microseconds
since the Unix epoch in UTC.
TIMESTAMPTZ shares TIMESTAMP’s 8-byte i64 storage; only the logical
type differs.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TIMESTAMPTZtype.
Sourcepub const unsafe fn write_timestamp_s(
&mut self,
idx: usize,
seconds_since_epoch: i64,
)
pub const unsafe fn write_timestamp_s( &mut self, idx: usize, seconds_since_epoch: i64, )
Writes a TIMESTAMP_S value at row idx, as seconds since the epoch.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TIMESTAMP_Stype.
Sourcepub const unsafe fn write_timestamp_ms(
&mut self,
idx: usize,
millis_since_epoch: i64,
)
pub const unsafe fn write_timestamp_ms( &mut self, idx: usize, millis_since_epoch: i64, )
Writes a TIMESTAMP_MS value at row idx, as milliseconds since the
epoch.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TIMESTAMP_MStype.
Sourcepub const unsafe fn write_timestamp_ns(
&mut self,
idx: usize,
nanos_since_epoch: i64,
)
pub const unsafe fn write_timestamp_ns( &mut self, idx: usize, nanos_since_epoch: i64, )
Writes a TIMESTAMP_NS value at row idx, as nanoseconds since the
epoch.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TIMESTAMP_NStype.
Sourcepub const unsafe fn write_time_tz(&mut self, idx: usize, bits: u64)
pub const unsafe fn write_time_tz(&mut self, idx: usize, bits: u64)
Writes a TIME WITH TIME ZONE value at row idx.
bits is DuckDB’s packed representation; build one with
datetime::time_tz_bits rather than
assembling it by hand.
§Safety
idxmust be within the vector’s capacity.- The vector must have
TIMETZtype.
Sourcepub const unsafe fn write_decimal(
&mut self,
idx: usize,
width: u8,
unscaled: i128,
)
pub const unsafe fn write_decimal( &mut self, idx: usize, width: u8, unscaled: i128, )
Writes a DECIMAL value at row idx from its unscaled representation.
DuckDB stores a DECIMAL in the narrowest integer that fits its
declared width — i16 up to 4 digits, i32 up to 9, i64 up to 18, and
i128 beyond — so the width must match the column’s type. Get it from
LogicalType::decimal_width.
§Safety
idxmust be within the vector’s capacity.- The vector must have
DECIMALtype with exactly thiswidth.
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 unsafe fn set_null_range(&mut self, range: Range<usize>)
pub unsafe fn set_null_range(&mut self, range: Range<usize>)
Sourcepub unsafe fn set_valid(&mut self, idx: usize)
pub unsafe fn set_valid(&mut self, idx: usize)
Marks row idx as valid (non-NULL) in the output vector.
Use this to undo a previous set_null call for a row,
or to explicitly mark a row as valid after writing its value.
Like set_null, this calls ensure_validity_writable
before modifying the validity bitmap.
§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.