quack_rs/vector/ops.rs
1// SPDX-License-Identifier: MIT
2// Copyright 2026 Tom F. <https://github.com/tomtom215/>
3// My way of giving something small back to the open source community
4// and encouraging more Rust development!
5
6//! Whole-vector operations (`DuckDB` 1.5.0+).
7//!
8//! [`SelectionVector`] is `DuckDB`'s
9//! zero-copy filtering primitive — and on its own it does nothing. These are the
10//! operations that consume one, plus the standalone [`OwnedVector`] that gives a
11//! copy somewhere to land.
12//!
13//! # The one thing to know before slicing
14//!
15//! [`slice()`] turns its vector into a **dictionary vector**: the payload stays
16//! put and the vector gains an indirection through the selection. That is the
17//! point — no data is copied — but it also means
18//! `duckdb_vector_get_data` no longer maps row `i` to element `i`, so a
19//! [`VectorReader`][crate::vector::VectorReader] over a sliced vector reads the
20//! wrong rows, silently.
21//!
22//! quack-rs's readers are flat readers, which is correct everywhere `DuckDB`
23//! hands an extension a vector — `CAPIScalarFunction`, `CAPIAggregateUpdate`,
24//! the cast bridge and the copy sink all call `Flatten()` on their inputs first
25//! (verified in `DuckDB` 1.5.4's `src/main/capi/*.cpp`), and
26//! `duckdb_fetch_chunk` flattens query results. Three operations can make a
27//! vector non-flat, and after each the guarantee has to be re-established by
28//! hand: [`slice()`] (a dictionary vector), [`reference_value()`] (a constant
29//! vector) and [`reference_vector()`] from a non-flat source (the target takes
30//! the source's layout). `arrow::data_chunk_from_arrow` also receives non-flat
31//! vectors from `DuckDB` — dictionary vectors for dictionary-encoded columns,
32//! constant vectors for null-typed ones — and flattens them itself before
33//! returning.
34//!
35//! Prefer [`copy_selected()`]: it writes the selected rows into a flat
36//! destination, which every reader in this crate can then read normally.
37//!
38//! # Example: filter without copying the payload
39//!
40//! ```rust,no_run
41//! use quack_rs::selection_vector::SelectionVector;
42//! use quack_rs::vector::ops::{copy_selected, OwnedVector};
43//! use quack_rs::types::{LogicalType, TypeId};
44//!
45//! # fn demo(src: libduckdb_sys::duckdb_vector, row_count: usize)
46//! # -> Result<(), quack_rs::error::ExtensionError> {
47//! // Keep every third row.
48//! let kept: Vec<u32> = (0..row_count as u32).step_by(3).collect();
49//! let mut sel = SelectionVector::new(kept.len())?;
50//! sel.as_mut_slice().copy_from_slice(&kept);
51//!
52//! let dst = OwnedVector::new(&LogicalType::new(TypeId::BigInt), kept.len())?;
53//! // SAFETY: `src` holds BIGINT, every index in `sel` is a valid `src` row,
54//! // and `dst` has room for `kept.len()` of them.
55//! unsafe { copy_selected(src, dst.as_raw(), &sel, kept.len(), 0, 0) };
56//! # Ok(())
57//! # }
58//! ```
59
60use libduckdb_sys::{duckdb_logical_type, duckdb_vector, idx_t};
61
62use crate::error::ExtensionError;
63use crate::selection_vector::SelectionVector;
64use crate::types::LogicalType;
65use crate::value::Value;
66
67/// The most elements [`OwnedVector::new`] will ask `DuckDB` to put in one vector.
68///
69/// This is `DConstants::MAX_VECTOR_SIZE` (2^37), the same ceiling `DuckDB`
70/// enforces when a list child vector grows (`VectorListBuffer::Reserve`).
71///
72/// It applies to the vector itself and to every child vector it creates. An
73/// `ARRAY(T, n)` child holds `capacity * n` elements, so an array type lowers
74/// the usable row capacity accordingly. Every physical element is at most 16
75/// bytes, so a vector within this bound needs at most 2 TiB and its size can
76/// never wrap a 64-bit multiply.
77///
78/// On a 32-bit target (wasm32) the allocation is the tighter bound: `DuckDB`
79/// narrows a buffer's 64-bit size to `size_t` when it allocates, so a vector
80/// of 2^32 bytes or more would get a wrapped, undersized buffer. There the
81/// bound is the most 16-byte elements whose bytes fit a `usize`, 2^28 - 1.
82#[allow(
83 clippy::cast_possible_truncation,
84 reason = "at most usize::MAX / 16 or 2^37, whichever is smaller, so it fits"
85)]
86pub const MAX_CAPACITY: usize =
87 max_capacity_within(crate::vector::list_builder::MAX_ALLOCATION_BYTES) as usize;
88
89/// [`MAX_CAPACITY`] for an allocation limit of `allocation_bytes`: 2^37, or
90/// the most 16-byte elements (the widest physical type) that fit it.
91const fn max_capacity_within(allocation_bytes: u64) -> u64 {
92 let fitting = allocation_bytes / 16;
93 if fitting < crate::vector::list_builder::MAX_LIST_CHILD_CAPACITY {
94 fitting
95 } else {
96 crate::vector::list_builder::MAX_LIST_CHILD_CAPACITY
97 }
98}
99
100/// The largest number of elements any single vector — `ty` itself or a child
101/// vector `DuckDB` allocates for it — would hold for a `rows`-row vector of
102/// `ty`, or `None` if that number does not fit in a `u64` (or `DuckDB`
103/// returned no child type, which it does not for a well-formed type).
104///
105/// Mirrors `Vector::Initialize` and its buffers in `DuckDB`'s
106/// `src/common/types/vector.cpp` / `vector_buffer.cpp`: `STRUCT` and `UNION`
107/// children, the `LIST` child and both `MAP` children are created with the
108/// parent's capacity; an `ARRAY(T, n)` child with `capacity * n`.
109///
110/// # Safety
111///
112/// `ty` must be a valid logical type handle.
113unsafe fn max_elements_per_vector(ty: duckdb_logical_type, rows: u64) -> Option<u64> {
114 use libduckdb_sys::{
115 DUCKDB_TYPE_DUCKDB_TYPE_ARRAY as ARRAY, DUCKDB_TYPE_DUCKDB_TYPE_LIST as LIST,
116 DUCKDB_TYPE_DUCKDB_TYPE_MAP as MAP, DUCKDB_TYPE_DUCKDB_TYPE_STRUCT as STRUCT,
117 DUCKDB_TYPE_DUCKDB_TYPE_UNION as UNION,
118 };
119 // SAFETY: `ty` is valid per this function's contract. Each child handle
120 // returned below is owned, and `LogicalType::from_raw` destroys it.
121 unsafe {
122 let child = |raw: duckdb_logical_type, child_rows: u64| {
123 if raw.is_null() {
124 return None;
125 }
126 let owned = LogicalType::from_raw(raw);
127 max_elements_per_vector(owned.as_raw(), child_rows)
128 };
129 let mut most = rows;
130 match libduckdb_sys::duckdb_get_type_id(ty) {
131 ARRAY => {
132 let size = libduckdb_sys::duckdb_array_type_array_size(ty);
133 let child_rows = rows.checked_mul(size)?;
134 most = most.max(child(
135 libduckdb_sys::duckdb_array_type_child_type(ty),
136 child_rows,
137 )?);
138 }
139 LIST => {
140 most = most.max(child(libduckdb_sys::duckdb_list_type_child_type(ty), rows)?);
141 }
142 MAP => {
143 most = most.max(child(libduckdb_sys::duckdb_map_type_key_type(ty), rows)?);
144 most = most.max(child(libduckdb_sys::duckdb_map_type_value_type(ty), rows)?);
145 }
146 STRUCT => {
147 for i in 0..libduckdb_sys::duckdb_struct_type_child_count(ty) {
148 most = most.max(child(
149 libduckdb_sys::duckdb_struct_type_child_type(ty, i),
150 rows,
151 )?);
152 }
153 }
154 UNION => {
155 for i in 0..libduckdb_sys::duckdb_union_type_member_count(ty) {
156 most = most.max(child(
157 libduckdb_sys::duckdb_union_type_member_type(ty, i),
158 rows,
159 )?);
160 }
161 }
162 _ => {}
163 }
164 Some(most)
165 }
166}
167
168/// A flat `duckdb_vector` this crate allocated, destroyed on drop.
169///
170/// `DuckDB` normally hands an extension the vectors it should read or write.
171/// This is for the cases where an extension needs one of its own: a
172/// destination for [`copy_selected`], a staging buffer, or a vector to hand to
173/// [`Appender::append_chunk`][crate::appender::Appender::append_chunk].
174///
175/// Requires `duckdb-1-5`: `duckdb_create_vector` sits in the unstable region of
176/// the C API struct.
177#[derive(Debug)]
178pub struct OwnedVector {
179 vector: duckdb_vector,
180}
181
182impl OwnedVector {
183 /// Allocates a flat vector of `logical_type` with room for `capacity` rows.
184 ///
185 /// # Errors
186 ///
187 /// Returns an error, before anything is allocated, if `capacity` — or
188 /// `capacity` times the sizes of the `ARRAY` types nested in
189 /// `logical_type` — exceeds [`MAX_CAPACITY`]. Also returns an error if
190 /// `DuckDB` refuses to allocate the vector: an `INVALID` or `ANY` type, or
191 /// an allocation that fails.
192 ///
193 /// The capacity check is not optional hygiene. `DuckDB` sizes the buffer
194 /// as `capacity * element_size` with an unchecked multiply
195 /// (`VectorBuffer::CreateStandardVector`, `vector_buffer.cpp`), and an
196 /// `ARRAY` child as `capacity * array_size`, also unchecked. A capacity
197 /// that wraps gets a small buffer and a success return, and writes inside
198 /// the capacity this function reported would then overflow the heap.
199 pub fn new(logical_type: &LogicalType, capacity: usize) -> Result<Self, ExtensionError> {
200 let rows = u64::try_from(capacity).unwrap_or(u64::MAX);
201 // SAFETY: `logical_type` is a live handle for the duration of the call.
202 let elements = unsafe { max_elements_per_vector(logical_type.as_raw(), rows) };
203 match elements {
204 Some(n) if n <= MAX_CAPACITY as u64 => {}
205 _ => {
206 return Err(ExtensionError::new(format!(
207 "OwnedVector capacity {capacity} is out of range: the vector (or an \
208 ARRAY child, which holds capacity * array_size elements) would exceed \
209 DuckDB's maximum of {MAX_CAPACITY} elements per vector"
210 )));
211 }
212 }
213 // SAFETY: `logical_type` is a live handle for the duration of the call;
214 // DuckDB returns an owned vector or null. `rows` fits in `idx_t` because
215 // it is at most `MAX_CAPACITY`.
216 let vector = unsafe { libduckdb_sys::duckdb_create_vector(logical_type.as_raw(), rows) };
217 if vector.is_null() {
218 return Err(ExtensionError::new(
219 "duckdb_create_vector returned null: the logical type cannot back a vector \
220 (ANY and INVALID cannot), or the capacity is out of range",
221 ));
222 }
223 Ok(Self { vector })
224 }
225
226 /// Returns the raw handle. Do not destroy it — this value still owns it.
227 #[must_use]
228 pub const fn as_raw(&self) -> duckdb_vector {
229 self.vector
230 }
231
232 /// Relinquishes ownership, returning the raw handle.
233 ///
234 /// The caller becomes responsible for `duckdb_destroy_vector`.
235 #[must_use]
236 pub const fn into_raw(self) -> duckdb_vector {
237 let raw = self.vector;
238 std::mem::forget(self);
239 raw
240 }
241}
242
243impl Drop for OwnedVector {
244 // The only effect is a `duckdb_destroy_vector`, which needs a live engine to
245 // reach and a leak checker to observe. That is what CI's LeakSanitizer job
246 // over the end-to-end suite is for; a `--lib` run cannot see it.
247 #[cfg_attr(test, mutants::skip)]
248 fn drop(&mut self) {
249 // SAFETY: `self.vector` was allocated by `duckdb_create_vector` and is
250 // destroyed exactly once.
251 unsafe { libduckdb_sys::duckdb_destroy_vector(&raw mut self.vector) };
252 }
253}
254
255/// Copies the rows `sel` names from `src` into `dst`.
256///
257/// The destination stays **flat**, so the ordinary
258/// [`VectorReader`][crate::vector::VectorReader] reads it correctly — which is
259/// why this is the filtering primitive to reach for first, ahead of [`slice()`].
260///
261/// `duckdb.h` on the offsets: `src_count` is "the number of entries from
262/// selection vector to copy … the effective length of the selection vector
263/// starting from index 0", `src_offset` is "the offset in the selection vector
264/// to copy from (important: actual number of items copied = `src_count` -
265/// `src_offset`)", and `dst_offset` is where in `dst` to start writing. So to copy
266/// all of `sel`, pass `src_count = sel.len()` and `src_offset = 0`.
267///
268/// # Safety
269///
270/// - `src` and `dst` must be valid vectors of the **same** logical type.
271/// - Every index in `sel[src_offset..src_count]` must be a valid row of `src`.
272/// - `dst` must have room for `dst_offset + (src_count - src_offset)` rows.
273/// - `src_offset <= src_count <= sel.len()`.
274pub unsafe fn copy_selected(
275 src: duckdb_vector,
276 dst: duckdb_vector,
277 sel: &SelectionVector,
278 src_count: usize,
279 src_offset: usize,
280 dst_offset: usize,
281) {
282 // SAFETY: forwarded from this function's own contract.
283 unsafe {
284 libduckdb_sys::duckdb_vector_copy_sel(
285 src,
286 dst,
287 sel.as_raw(),
288 idx_t::try_from(src_count).unwrap_or(idx_t::MAX),
289 idx_t::try_from(src_offset).unwrap_or(idx_t::MAX),
290 idx_t::try_from(dst_offset).unwrap_or(idx_t::MAX),
291 );
292 }
293}
294
295/// Reorders or filters `vector` in place through `sel`, without copying its
296/// payload.
297///
298/// # This makes the vector non-flat
299///
300/// `duckdb.h`: "Turns the vector into a dictionary vector." Row `i` of the
301/// result is element `sel[i]` of the original payload, so
302/// `duckdb_vector_get_data` — and therefore every
303/// [`VectorReader`][crate::vector::VectorReader] in this crate — no longer
304/// indexes it correctly. Nothing detects this at run time; the reads are simply
305/// wrong.
306///
307/// Use it when the vector's next stop is `DuckDB` itself, which understands
308/// dictionary vectors. When *you* need to read the result, use
309/// [`copy_selected`] into a flat destination instead.
310///
311/// # Safety
312///
313/// - `vector` must be a valid vector this extension owns or was handed to write.
314/// - `len` must not exceed the vector's length, and every index in `sel[..len]`
315/// must be a valid row of `vector`.
316/// - No [`VectorReader`][crate::vector::VectorReader] or
317/// [`VectorWriter`][crate::vector::VectorWriter] over `vector` may be used
318/// afterwards: both cache the pre-slice data pointer and both assume flat
319/// indexing.
320/// - `sel` must not be modified while `vector` is in use. `DuckDB` copies a
321/// `SelectionVector` by sharing its buffer (`selection_vector.hpp`), so the
322/// sliced vector reads through `sel`'s indices, not a copy of them: a later
323/// write through [`SelectionVector::as_mut_slice`] silently changes which
324/// rows `vector` holds. Dropping `sel` is fine — the shared buffer is
325/// reference-counted.
326///
327/// [`SelectionVector::as_mut_slice`]: crate::selection_vector::SelectionVector::as_mut_slice
328pub unsafe fn slice(vector: duckdb_vector, sel: &SelectionVector, len: usize) {
329 // SAFETY: forwarded from this function's own contract.
330 unsafe {
331 libduckdb_sys::duckdb_slice_vector(
332 vector,
333 sel.as_raw(),
334 idx_t::try_from(len).unwrap_or(idx_t::MAX),
335 );
336 }
337}
338
339/// Fills `vector` with a single constant value.
340///
341/// `duckdb.h`: "Copies the value from `value` to `vector`." This is how an
342/// extension emits "the same answer for every row" without writing it row by
343/// row, and it is what `DuckDB` does internally for a constant expression.
344///
345/// # Safety
346///
347/// - `vector` must be a valid, writable vector.
348/// - `value`'s logical type must equal the vector's exactly. `DuckDB` does not
349/// reinterpret a mismatched value: it sizes the buffers from the value's
350/// type, casts the value (aborting the process when the cast throws, as for
351/// `'abc'` into `BIGINT`), and writes data of the vector's type into those
352/// buffers, so a narrower value type can overflow them and a `NULL` of the
353/// wrong type (such as [`Value::null_value`]) leaves a `LIST` vector without
354/// its child buffer. To fill a vector with `NULL`, use a typed `NULL` of the
355/// vector's own type.
356/// - As with [`slice()`], the result is not a flat vector: do not read it back
357/// through a [`VectorReader`][crate::vector::VectorReader].
358pub unsafe fn reference_value(vector: duckdb_vector, value: &Value) {
359 // SAFETY: forwarded from this function's own contract; `value` outlives the
360 // call and DuckDB copies from it.
361 unsafe { libduckdb_sys::duckdb_vector_reference_value(vector, value.as_raw()) };
362}
363
364/// Makes `to` reference `from`'s data instead of its own.
365///
366/// `duckdb.h`: "Changes `to_vector` to reference `from_vector`. After, the
367/// vectors share ownership of the data." No payload is copied. That ownership
368/// does not always reach the bytes: a column other than the first of a chunk
369/// from `arrow::data_chunk_from_arrow` (`duckdb-1-5-4`) points
370/// into Arrow buffers that only column 0 keeps alive.
371///
372/// # Safety
373///
374/// - Both vectors must be valid and of the same logical type.
375/// - `from` must outlive every read of `to`.
376/// - Any [`VectorReader`][crate::vector::VectorReader] or
377/// [`VectorWriter`][crate::vector::VectorWriter] built over `to` before this
378/// call caches the old data pointer and must not be used afterwards.
379pub unsafe fn reference_vector(to: duckdb_vector, from: duckdb_vector) {
380 // SAFETY: forwarded from this function's own contract.
381 unsafe { libduckdb_sys::duckdb_vector_reference_vector(to, from) };
382}
383
384#[cfg(test)]
385mod tests {
386 #[cfg(feature = "_duckdb-testing")]
387 use super::*;
388
389 /// `OwnedVector::new` refuses anything above `DuckDB`'s
390 /// `DConstants::MAX_VECTOR_SIZE` (2^37 elements) — and nothing below it —
391 /// on a 64-bit target. On a 32-bit one the allocation binds first: 2^28 - 1
392 /// elements of 16 bytes fit a `u32`, 2^28 do not.
393 #[test]
394 fn max_capacity_is_duckdbs_max_vector_size_or_what_one_allocation_holds() {
395 #[cfg(target_pointer_width = "64")]
396 assert_eq!(super::MAX_CAPACITY, 137_438_953_472);
397 assert_eq!(super::max_capacity_within(u64::MAX), 1 << 37);
398 let wasm32 = u64::from(u32::MAX);
399 assert_eq!(super::max_capacity_within(wasm32), (1 << 28) - 1);
400 assert!(super::max_capacity_within(wasm32) * 16 <= wasm32);
401 assert!(usize::try_from(super::MAX_CAPACITY as u64 * 16).is_ok());
402 }
403 #[cfg(feature = "_duckdb-testing")]
404 use crate::types::TypeId;
405
406 #[test]
407 #[cfg(feature = "_duckdb-testing")]
408 fn an_owned_vector_round_trips_values() {
409 let _db = crate::testing::InMemoryDb::open().expect("dispatch table");
410 let ty = LogicalType::new(TypeId::BigInt);
411 let vector = OwnedVector::new(&ty, 16).expect("allocate");
412 assert!(!vector.as_raw().is_null());
413
414 // SAFETY: the vector holds BIGINT and has capacity 16.
415 let mut writer = unsafe { crate::vector::VectorWriter::from_vector(vector.as_raw()) };
416 for row in 0..16 {
417 // SAFETY: `row` is within the capacity declared above.
418 unsafe { writer.write_i64(row, i64::try_from(row).unwrap() * 10) };
419 }
420 // SAFETY: the vector holds 16 BIGINT rows written just above.
421 let reader = unsafe { crate::vector::VectorReader::from_vector(vector.as_raw(), 16) };
422 for row in 0..16 {
423 // SAFETY: `row < 16`.
424 assert_eq!(
425 unsafe { reader.read_i64(row) },
426 i64::try_from(row).unwrap() * 10
427 );
428 }
429 }
430
431 #[test]
432 #[cfg(feature = "_duckdb-testing")]
433 fn copy_selected_lands_flat_and_readable() {
434 let _db = crate::testing::InMemoryDb::open().expect("dispatch table");
435 let ty = LogicalType::new(TypeId::BigInt);
436 let src = OwnedVector::new(&ty, 32).expect("allocate src");
437 let dst = OwnedVector::new(&ty, 32).expect("allocate dst");
438
439 // SAFETY: `src` holds 32 BIGINT rows.
440 let mut writer = unsafe { crate::vector::VectorWriter::from_vector(src.as_raw()) };
441 for row in 0..32 {
442 // SAFETY: `row < 32`.
443 unsafe { writer.write_i64(row, i64::try_from(row).unwrap()) };
444 }
445
446 // Keep the odd rows, in reverse.
447 let kept: Vec<u32> = (0..32u32).filter(|i| i % 2 == 1).rev().collect();
448 let mut sel = SelectionVector::new(kept.len()).expect("allocate");
449 sel.as_mut_slice().copy_from_slice(&kept);
450
451 // SAFETY: same type, every index is a valid `src` row, `dst` has room.
452 unsafe { copy_selected(src.as_raw(), dst.as_raw(), &sel, kept.len(), 0, 0) };
453
454 // SAFETY: `dst` is flat and holds `kept.len()` BIGINT rows.
455 let reader = unsafe { crate::vector::VectorReader::from_vector(dst.as_raw(), kept.len()) };
456 for (row, &want) in kept.iter().enumerate() {
457 // SAFETY: `row < kept.len()`.
458 assert_eq!(
459 unsafe { reader.read_i64(row) },
460 i64::from(want),
461 "copy_selected must preserve the selection's order"
462 );
463 }
464 }
465
466 /// Regression: `DuckDB` sizes the buffer with an unchecked
467 /// `capacity * element_size`, so `(2^60 + 2)` HUGEINT rows (16 bytes each)
468 /// wrapped to a 32-byte allocation that `new` reported as success. Writing
469 /// rows inside the reported capacity then overflowed the heap into
470 /// neighbouring allocations.
471 #[test]
472 #[cfg(feature = "_duckdb-testing")]
473 fn a_capacity_whose_byte_size_wraps_is_refused() {
474 let _db = crate::testing::InMemoryDb::open().expect("dispatch table");
475 let hugeint = LogicalType::new(TypeId::HugeInt);
476 let err = OwnedVector::new(&hugeint, (1_usize << 60) + 2).expect_err("must refuse");
477 assert!(err.as_str().contains("out of range"), "{err}");
478 assert!(OwnedVector::new(&LogicalType::new(TypeId::BigInt), 1 << 61).is_err());
479 assert!(OwnedVector::new(&hugeint, MAX_CAPACITY + 1).is_err());
480 }
481
482 /// An `ARRAY(T, n)` child holds `capacity * n` elements, so the bound must
483 /// apply to that product, including through a `STRUCT` and a `LIST`.
484 #[test]
485 #[cfg(feature = "_duckdb-testing")]
486 fn an_array_child_counts_against_the_capacity_bound() {
487 let _db = crate::testing::InMemoryDb::open().expect("dispatch table");
488 let arr = LogicalType::array(TypeId::BigInt, 1000);
489 // 2^28 rows * 1000 elements > 2^37.
490 assert!(OwnedVector::new(&arr, 1 << 28).is_err());
491 assert!(OwnedVector::new(&arr, 2048).is_ok());
492
493 // 99_999 is the largest size `duckdb_create_array_type` accepts.
494 let nested = LogicalType::struct_type_from_logical(&[(
495 "xs",
496 LogicalType::list_from_logical(&LogicalType::array(TypeId::Integer, 99_999)),
497 )]);
498 // 2^21 rows * 99_999 elements > 2^37, reached through STRUCT -> LIST -> ARRAY.
499 assert!(OwnedVector::new(&nested, 1 << 21).is_err());
500 assert!(OwnedVector::new(&nested, 4).is_ok());
501
502 // 99_999^4 does not fit in a u64: the element count itself overflows,
503 // and even a single row must be refused rather than wrapped.
504 let mut deep = LogicalType::array(TypeId::TinyInt, 99_999);
505 for _ in 0..3 {
506 deep = LogicalType::array_from_logical(&deep, 99_999);
507 }
508 assert!(OwnedVector::new(&deep, 1).is_err());
509 }
510
511 #[test]
512 #[cfg(feature = "_duckdb-testing")]
513 fn creating_a_vector_of_an_unusable_type_is_an_error() {
514 let _db = crate::testing::InMemoryDb::open().expect("dispatch table");
515 // ANY cannot back a vector; DuckDB returns null rather than throwing.
516 let ty = LogicalType::new(TypeId::Any);
517 assert!(OwnedVector::new(&ty, 8).is_err());
518 }
519}