Expand description
Safe typed writing to DuckDB result vectors.
VectorWriter provides safe methods for writing typed values and NULL
flags to a DuckDB output vector from within a finalize callback.
§Pitfall L4: ensure_validity_writable
When writing NULL values, you must call duckdb_vector_ensure_validity_writable
before duckdb_vector_get_validity. A vector with no NULLs yet usually has no
validity mask at all, and then get_validity returns NULL; the
duckdb_validity_set_row_* functions return early on a NULL mask, so the
NULL is silently dropped and the row reads back as a valid value.
VectorWriter::set_null calls ensure_validity_writable automatically.
§NULLs in nested vectors
Marking a STRUCT or ARRAY row NULL also marks its children NULL — every
field of the struct row, every element of the array row, recursively —
exactly as DuckDB’s internal FlatVector::SetNull does. Without that,
struct_extract(s, 'a') on a NULL row returns whatever was last written to
field a. LIST and MAP children are not touched, matching DuckDB.
Structs§
- Vector
Writer - A typed writer for a
DuckDBoutput vector in afinalizecallback.