Skip to main content

Module string

Module string 

Source
Expand description

DuckDB VARCHAR and BLOB (duckdb_string_t) reading utilities.

§Pitfall P7: Undocumented duckdb_string_t format

DuckDB stores VARCHAR values in a 16-byte duckdb_string_t struct with two representations:

  • Inline (length ≤ 12): [ len: u32 | data: [u8; 12] ]
  • Pointer (length > 12): [ len: u32 | prefix: [u8; 4] | ptr: *const u8 ], the pointer at offset 8 (on a 32-bit target it takes 4 bytes and 4 bytes of padding follow)

This is not documented in the Rust bindings. The layout was determined by reading DuckDB’s C source and confirmed by the duckdb-behavioral implementation.

§Example

use quack_rs::vector::string::{DuckStringView, read_duck_string};

// A short string (inline case)
let bytes: [u8; 16] = {
    let mut b = [0u8; 16];
    b[0] = 5; // length = 5
    b[4..9].copy_from_slice(b"hello");
    b
};
let view = DuckStringView::inline_from_bytes(&bytes).expect("inline value");
assert_eq!(view.as_str(), Some("hello"));
assert_eq!(view.len(), 5);

Structs§

DuckStringView
A parsed view of a duckdb_string_t value.

Constants§

DUCK_STRING_INLINE_MAX_LEN
The maximum string length that fits inline in a duckdb_string_t (≤12 bytes).
DUCK_STRING_SIZE
The size of a duckdb_string_t in bytes.
MAX_STRING_LEN
The longest VARCHAR or BLOB value DuckDB can store, in bytes: string_t::MAX_STRING_SIZE, which is u32::MAX because the length field of a duckdb_string_t is a u32.

Functions§

check_string_len
Returns an error if len exceeds MAX_STRING_LEN.
read_duck_blob⚠
Reads a DuckDB BLOB value at the given row index.
read_duck_string⚠
Reads a DuckDB VARCHAR value from a raw vector data pointer at a given row index.