Skip to main content

VectorWriter

Struct VectorWriter 

Source
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

Source

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.

Source

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.

Source

pub const unsafe fn write_i8(&mut self, idx: usize, value: i8)

Writes an i8 (TINYINT) value at row idx.

§Safety
  • idx must be within the vector’s capacity.
  • The vector must have TINYINT type.
Source

pub const unsafe fn write_i16(&mut self, idx: usize, value: i16)

Writes an i16 (SMALLINT) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_i32(&mut self, idx: usize, value: i32)

Writes an i32 (INTEGER) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_i64(&mut self, idx: usize, value: i64)

Writes an i64 (BIGINT / TIMESTAMP) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_u8(&mut self, idx: usize, value: u8)

Writes a u8 (UTINYINT) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_u32(&mut self, idx: usize, value: u32)

Writes a u32 (UINTEGER) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_u64(&mut self, idx: usize, value: u64)

Writes a u64 (UBIGINT) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_f32(&mut self, idx: usize, value: f32)

Writes an f32 (FLOAT) value at row idx.

§Safety

See write_i8.

Source

pub const unsafe fn write_f64(&mut self, idx: usize, value: f64)

Writes an f64 (DOUBLE) value at row idx.

§Safety

See write_i8.

Source

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
  • idx must be within the vector’s capacity.
  • The vector must have BOOLEAN type.
Source

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
  • idx must be within the vector’s capacity.
  • The vector must have HUGEINT type.
Source

pub const unsafe fn write_u16(&mut self, idx: usize, value: u16)

Writes a u16 (USMALLINT) value at row idx.

§Safety

See write_i8.

Source

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
  • idx must be within the vector’s capacity.
  • The vector must have VARCHAR type.
Source

pub const unsafe fn write_date(&mut self, idx: usize, days_since_epoch: i32)

Writes a DATE value at row idx as days since the Unix epoch.

DuckDB stores DATE as a 4-byte i32. This is a semantic alias for write_i32.

§Safety
  • idx must be within the vector’s capacity.
  • The vector must have DATE type.
Source

pub const unsafe fn write_timestamp( &mut self, idx: usize, micros_since_epoch: i64, )

Writes a TIMESTAMP value at row idx as microseconds since the Unix epoch.

DuckDB stores TIMESTAMP as an 8-byte i64. This is a semantic alias for write_i64.

§Safety
  • idx must be within the vector’s capacity.
  • The vector must have TIMESTAMP type.
Source

pub const unsafe fn write_time( &mut self, idx: usize, micros_since_midnight: i64, )

Writes a TIME value at row idx as microseconds since midnight.

DuckDB stores TIME as an 8-byte i64. This is a semantic alias for write_i64.

§Safety
  • idx must be within the vector’s capacity.
  • The vector must have TIME type.
Source

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
  • idx must be within the vector’s capacity.
  • The vector must have INTERVAL type.
Source

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
  • idx must be within the vector’s capacity.
  • The vector must have BLOB type.
Source

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
  • idx must be within the vector’s capacity.
  • The vector must have UUID type.
Source

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
  • idx must be within the vector’s capacity.
  • The vector must have VARCHAR type.
Source

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
  • idx must be within the vector’s capacity.
Source

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
  • idx must be within the vector’s capacity.
Source

pub const fn as_raw(&self) -> duckdb_vector

Returns the underlying raw vector handle.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.