Skip to main content

Module complex

Module complex 

Source
Expand description

Complex type vector operations: STRUCT fields, LIST elements, MAP entries.

DuckDB stores complex types as nested vectors:

  • STRUCT: a parent vector with N child vectors, one per field.
  • LIST: a parent vector holding duckdb_list_entry { offset, length } per row, plus a single flat child vector containing all elements end-to-end.
  • MAP: stored as LIST<STRUCT{key, value}> — the list’s child vector is a STRUCT with two children: key (index 0) and value (index 1).

§Reading vs writing

§Example: Reading a STRUCT column

use quack_rs::vector::{VectorReader, complex::StructVector};
use libduckdb_sys::{duckdb_data_chunk, duckdb_data_chunk_get_vector};

// Inside a table function scan callback:
// let parent_vec = unsafe { duckdb_data_chunk_get_vector(chunk, 0) };
// let x_vec = StructVector::get_child(parent_vec, 0); // field index 0
// let x_reader = unsafe { VectorReader::from_vector(x_vec, row_count) };
// let x: f64 = unsafe { x_reader.read_f64(row_idx) };

§Example: Writing a LIST column

use quack_rs::vector::{VectorWriter, complex::ListVector};
use libduckdb_sys::{duckdb_data_chunk_get_vector, duckdb_data_chunk};

// Inside a scan callback:
// let list_vec = unsafe { duckdb_data_chunk_get_vector(output, 0) };
// // Write 3 elements for row 0: [10, 20, 30]
// ListVector::reserve(list_vec, 3);
// ListVector::set_size(list_vec, 3);
// // Write the list offset/length entry for row 0.
// ListVector::set_entry(list_vec, 0, 0, 3); // row=0, offset=0, length=3
// // Write values into the child vector.
// let child = ListVector::get_child(list_vec);
// let mut writer = unsafe { VectorWriter::from_vector(child) };
// unsafe { writer.write_i64(0, 10); writer.write_i64(1, 20); writer.write_i64(2, 30); }

Structs§

ArrayVector
Helpers for working with ARRAY vectors (fixed-size arrays).
ListVector
Operations on LIST vectors.
MapVector
Operations on MAP vectors.
StructVector
Operations on STRUCT vectors (accessing child field vectors).