Skip to main content

MockVectorWriter

Struct MockVectorWriter 

Source
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_null clears a validity bit and a later write_* does not set it again — a real vector keeps returning NULL for that row. Use set_valid to undo a NULL.
  • A row that is never written is valid, not NULL. DuckDB hands out output vectors whose rows are all valid and whose data is whatever the buffer last held, so a callback that forgets set_null returns garbage. Here such a row reports is_null == false and is_written == false, so a test can catch it.
  • Capacity is fixed. Writing at or past the capacity given to new panics; on a real vector it is out-of-bounds memory access.
  • Strings over MAX_STRING_LEN panic, as VectorWriter::write_varchar does.

Implementations§

Source§

impl MockVectorWriter

Source

pub fn new(capacity: usize) -> Self

Creates a writer with room for capacity rows, all valid and unwritten.

Source

pub fn set_null(&mut self, idx: usize)

Marks row idx as NULL. A later write_* does not undo this; see set_valid.

§Panics

Panics if idx is not less than the capacity.

Source

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the capacity: the number of rows this mock holds.

Source

pub fn is_empty(&self) -> bool

Returns true if the capacity is zero.

Source

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.

Source

pub fn write_i8(&mut self, idx: usize, value: i8)

Writes a TINYINT value at row idx.

Source

pub fn write_i16(&mut self, idx: usize, value: i16)

Writes a SMALLINT value at row idx.

Source

pub fn write_i32(&mut self, idx: usize, value: i32)

Writes an INTEGER value at row idx.

Source

pub fn write_i64(&mut self, idx: usize, value: i64)

Writes a BIGINT value at row idx.

Source

pub fn write_u8(&mut self, idx: usize, value: u8)

Writes a UTINYINT value at row idx.

Source

pub fn write_u16(&mut self, idx: usize, value: u16)

Writes a USMALLINT value at row idx.

Source

pub fn write_u32(&mut self, idx: usize, value: u32)

Writes a UINTEGER value at row idx.

Source

pub fn write_u64(&mut self, idx: usize, value: u64)

Writes a UBIGINT value at row idx.

Source

pub fn write_f32(&mut self, idx: usize, value: f32)

Writes a FLOAT value at row idx.

Source

pub fn write_f64(&mut self, idx: usize, value: f64)

Writes a DOUBLE value at row idx.

Source

pub fn write_bool(&mut self, idx: usize, value: bool)

Writes a BOOLEAN value at row idx.

Source

pub fn write_i128(&mut self, idx: usize, value: i128)

Writes a HUGEINT value at row idx.

Source

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.

Source

pub fn write_str(&mut self, idx: usize, value: &str)

Writes a VARCHAR value at row idx.

Alias for write_varchar.

Source

pub fn write_interval(&mut self, idx: usize, value: DuckInterval)

Writes an INTERVAL value at row idx.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn try_get_i64(&self, idx: usize) -> Option<i64>

Returns the BIGINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_i32(&self, idx: usize) -> Option<i32>

Returns the INTEGER value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_f64(&self, idx: usize) -> Option<f64>

Returns the DOUBLE value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_bool(&self, idx: usize) -> Option<bool>

Returns the BOOLEAN value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_str(&self, idx: usize) -> Option<&str>

Returns the VARCHAR value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_interval(&self, idx: usize) -> Option<DuckInterval>

Returns the INTERVAL value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_i8(&self, idx: usize) -> Option<i8>

Returns the TINYINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_i16(&self, idx: usize) -> Option<i16>

Returns the SMALLINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_u8(&self, idx: usize) -> Option<u8>

Returns the UTINYINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_u16(&self, idx: usize) -> Option<u16>

Returns the USMALLINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_u32(&self, idx: usize) -> Option<u32>

Returns the UINTEGER value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_u64(&self, idx: usize) -> Option<u64>

Returns the UBIGINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_f32(&self, idx: usize) -> Option<f32>

Returns the FLOAT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_i128(&self, idx: usize) -> Option<i128>

Returns the HUGEINT value at row idx, or None if NULL or wrong type.

Source

pub fn try_get_blob(&self, idx: usize) -> Option<&[u8]>

Returns the BLOB value at row idx, or None if NULL or wrong type.

Source

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.

Trait Implementations§

Source§

impl Debug for MockVectorWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MockVectorWriter

Source§

fn default() -> MockVectorWriter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.