pub struct MockVectorWriter { /* private fields */ }Expand description
An in-memory mock output vector for testing finalize and scan callbacks.
Write typed values and NULL flags using the same method names as
VectorWriter. Inspect the results with
try_get_i64, is_null, etc.
§Example
use quack_rs::testing::{MockVectorWriter, MockDuckValue};
let mut w = MockVectorWriter::new(3);
w.write_i64(0, 42);
w.write_i64(1, -7);
w.set_null(2);
assert_eq!(w.try_get_i64(0), Some(42));
assert_eq!(w.try_get_i64(1), Some(-7));
assert!(w.is_null(2));§It behaves like a real output vector, including where that hurts
A mock that is more forgiving than DuckDB makes a test pass for code that
is wrong in production. So, as with a real vector (verified against
DuckDB 1.5.5):
- Validity is separate from data.
set_nullclears a validity bit and a laterwrite_*does not set it again — a real vector keeps returning NULL for that row. Useset_validto undo a NULL. - A row that is never written is valid, not NULL.
DuckDBhands out output vectors whose rows are all valid and whose data is whatever the buffer last held, so a callback that forgetsset_nullreturns garbage. Here such a row reportsis_null== falseandis_written== false, so a test can catch it. - Capacity is fixed. Writing at or past the capacity given to
newpanics; on a real vector it is out-of-bounds memory access. - Strings over
MAX_STRING_LENpanic, asVectorWriter::write_varchardoes.
Implementations§
Source§impl MockVectorWriter
impl MockVectorWriter
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a writer with room for capacity rows, all valid and unwritten.
Sourcepub fn set_valid(&mut self, idx: usize)
pub fn set_valid(&mut self, idx: usize)
Marks row idx as valid again, mirroring
VectorWriter::set_valid.
§Panics
Panics if idx is not less than the capacity.
Sourcepub fn is_null(&self, idx: usize) -> bool
pub fn is_null(&self, idx: usize) -> bool
Returns true if row idx has been marked NULL.
A row that was never written is not NULL — see the type-level docs.
§Panics
Panics if idx is not less than the capacity.
Sourcepub fn is_written(&self, idx: usize) -> bool
pub fn is_written(&self, idx: usize) -> bool
Returns true if a value has been written at row idx, whether or not
the row is also marked NULL.
§Panics
Panics if idx is not less than the capacity.
Sourcepub fn get(&self, idx: usize) -> Option<&MockDuckValue>
pub fn get(&self, idx: usize) -> Option<&MockDuckValue>
Returns the value at row idx as DuckDB would read it.
Returns None if the row is NULL, has never been written, or is out of
bounds. Use is_null and
is_written to tell those apart.
Sourcepub fn write_bool(&mut self, idx: usize, value: bool)
pub fn write_bool(&mut self, idx: usize, value: bool)
Writes a BOOLEAN value at row idx.
Sourcepub fn write_i128(&mut self, idx: usize, value: i128)
pub fn write_i128(&mut self, idx: usize, value: i128)
Writes a HUGEINT value at row idx.
Sourcepub fn write_varchar(&mut self, idx: usize, value: &str)
pub fn write_varchar(&mut self, idx: usize, value: &str)
Writes a VARCHAR value at row idx.
§Panics
Panics if idx is out of bounds or value is longer than
MAX_STRING_LEN.
Sourcepub fn write_str(&mut self, idx: usize, value: &str)
pub fn write_str(&mut self, idx: usize, value: &str)
Writes a VARCHAR value at row idx.
Alias for write_varchar.
Sourcepub fn write_interval(&mut self, idx: usize, value: DuckInterval)
pub fn write_interval(&mut self, idx: usize, value: DuckInterval)
Writes an INTERVAL value at row idx.
Sourcepub fn write_blob(&mut self, idx: usize, value: &[u8])
pub fn write_blob(&mut self, idx: usize, value: &[u8])
Writes a BLOB value at row idx.
§Panics
Panics if idx is out of bounds or value is longer than
MAX_STRING_LEN.
Sourcepub fn write_date(&mut self, idx: usize, days_since_epoch: i32)
pub fn write_date(&mut self, idx: usize, days_since_epoch: i32)
Writes a DATE value (days since epoch) at row idx.
Semantic alias for write_i32.
Sourcepub fn write_timestamp(&mut self, idx: usize, micros_since_epoch: i64)
pub fn write_timestamp(&mut self, idx: usize, micros_since_epoch: i64)
Writes a TIMESTAMP value (microseconds since epoch) at row idx.
Semantic alias for write_i64.
Sourcepub fn write_time(&mut self, idx: usize, micros_since_midnight: i64)
pub fn write_time(&mut self, idx: usize, micros_since_midnight: i64)
Writes a TIME value (microseconds since midnight) at row idx.
Semantic alias for write_i64.
Sourcepub fn write_uuid(&mut self, idx: usize, bits: u128)
pub fn write_uuid(&mut self, idx: usize, bits: u128)
Writes a UUID’s textual 128 bits at row idx.
Applies DuckDB’s top-bit flip exactly as
VectorWriter::write_uuid
does, so a callback tested against this mock behaves the same against a
real vector. write_i128 writes the raw storage.
Sourcepub fn try_get_i64(&self, idx: usize) -> Option<i64>
pub fn try_get_i64(&self, idx: usize) -> Option<i64>
Returns the BIGINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_i32(&self, idx: usize) -> Option<i32>
pub fn try_get_i32(&self, idx: usize) -> Option<i32>
Returns the INTEGER value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_f64(&self, idx: usize) -> Option<f64>
pub fn try_get_f64(&self, idx: usize) -> Option<f64>
Returns the DOUBLE value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_bool(&self, idx: usize) -> Option<bool>
pub fn try_get_bool(&self, idx: usize) -> Option<bool>
Returns the BOOLEAN value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_str(&self, idx: usize) -> Option<&str>
pub fn try_get_str(&self, idx: usize) -> Option<&str>
Returns the VARCHAR value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_interval(&self, idx: usize) -> Option<DuckInterval>
pub fn try_get_interval(&self, idx: usize) -> Option<DuckInterval>
Returns the INTERVAL value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_i8(&self, idx: usize) -> Option<i8>
pub fn try_get_i8(&self, idx: usize) -> Option<i8>
Returns the TINYINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_i16(&self, idx: usize) -> Option<i16>
pub fn try_get_i16(&self, idx: usize) -> Option<i16>
Returns the SMALLINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_u8(&self, idx: usize) -> Option<u8>
pub fn try_get_u8(&self, idx: usize) -> Option<u8>
Returns the UTINYINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_u16(&self, idx: usize) -> Option<u16>
pub fn try_get_u16(&self, idx: usize) -> Option<u16>
Returns the USMALLINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_u32(&self, idx: usize) -> Option<u32>
pub fn try_get_u32(&self, idx: usize) -> Option<u32>
Returns the UINTEGER value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_u64(&self, idx: usize) -> Option<u64>
pub fn try_get_u64(&self, idx: usize) -> Option<u64>
Returns the UBIGINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_f32(&self, idx: usize) -> Option<f32>
pub fn try_get_f32(&self, idx: usize) -> Option<f32>
Returns the FLOAT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_i128(&self, idx: usize) -> Option<i128>
pub fn try_get_i128(&self, idx: usize) -> Option<i128>
Returns the HUGEINT value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_blob(&self, idx: usize) -> Option<&[u8]>
pub fn try_get_blob(&self, idx: usize) -> Option<&[u8]>
Returns the BLOB value at row idx, or None if NULL or wrong type.
Sourcepub fn try_get_uuid(&self, idx: usize) -> Option<u128>
pub fn try_get_uuid(&self, idx: usize) -> Option<u128>
Returns the UUID’s textual 128 bits at row idx, or None if NULL or
wrong type.
Undoes DuckDB’s top-bit flip exactly as
VectorReader::read_uuid does.
try_get_i128 returns the raw storage.