Skip to main content

slice

Function slice 

Source
pub unsafe fn slice(vector: duckdb_vector, sel: &SelectionVector, len: usize)
Expand description

Reorders or filters vector in place through sel, without copying its payload.

§This makes the vector non-flat

duckdb.h: “Turns the vector into a dictionary vector.” Row i of the result is element sel[i] of the original payload, so duckdb_vector_get_data — and therefore every VectorReader in this crate — no longer indexes it correctly. Nothing detects this at run time; the reads are simply wrong.

Use it when the vector’s next stop is DuckDB itself, which understands dictionary vectors. When you need to read the result, use copy_selected into a flat destination instead.

§Safety

  • vector must be a valid vector this extension owns or was handed to write.
  • len must not exceed the vector’s length, and every index in sel[..len] must be a valid row of vector.
  • No VectorReader or VectorWriter over vector may be used afterwards: both cache the pre-slice data pointer and both assume flat indexing.
  • sel must not be modified while vector is in use. DuckDB copies a SelectionVector by sharing its buffer (selection_vector.hpp), so the sliced vector reads through sel’s indices, not a copy of them: a later write through SelectionVector::as_mut_slice silently changes which rows vector holds. Dropping sel is fine — the shared buffer is reference-counted.