Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/bool/vtable/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl OperatorVTable<BoolVTable> for BoolVTable {
// Note that validity already has the mask applied so we only need to apply it to bits.
let bits = bits.filter(&mask);

Ok(BoolVector::new(bits, validity).into())
Ok(BoolVector::try_new(bits, validity)?.into())
}))
}
}
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/primitive/vtable/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl OperatorVTable<PrimitiveVTable> for PrimitiveVTable {
// the elements.
let elements = elements.filter(&mask);

Ok(PVector::new(elements, validity).into())
Ok(PVector::try_new(elements, validity)?.into())
}))
})
}
Expand Down
8 changes: 7 additions & 1 deletion vortex-compute/src/filter/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use crate::filter::Filter;

impl Filter for BoolVector {
fn filter(&self, mask: &Mask) -> Self {
Self::new(self.bits().filter(mask), self.validity().filter(mask))
let filtered_bits = self.bits().filter(mask);
let filtered_validity = self.validity().filter(mask);

// SAFETY: We filter the bits and validity with the same mask, and since they came from an
// existing and valid `BoolVector`, we know that the filtered output must have the same
// length.
unsafe { Self::new_unchecked(filtered_bits, filtered_validity) }
}
}
1 change: 1 addition & 0 deletions vortex-vector/src/bool/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl FromIterator<bool> for BoolVectorMut {
///
/// It consumes the mutable vector and iterates over the elements, yielding `None` for null values
/// and `Some(value)` for valid values.
#[derive(Debug)]
pub struct BoolVectorMutIterator {
/// The vector being iterated over.
vector: BoolVectorMut,
Expand Down
19 changes: 8 additions & 11 deletions vortex-vector/src/bool/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ impl BoolVector {
///
/// Panics if the length of the validity mask does not match the length of the bits.
pub fn new(bits: BitBuffer, validity: Mask) -> Self {
Self::try_new(bits, validity)
.vortex_expect("`BoolVector` validity mask must have the same length as bits")
Self::try_new(bits, validity).vortex_expect("Failed to create `BoolVector`")
}

/// Tries to create a new [`BoolVector`] from the given bits and validity mask.
Expand All @@ -53,17 +52,15 @@ impl BoolVector {
/// # Safety
///
/// The caller must ensure that the validity mask has the same length as the bits.
pub fn new_unchecked(bits: BitBuffer, validity: Mask) -> Self {
debug_assert_eq!(
validity.len(),
bits.len(),
"`BoolVector` validity mask must have the same length as bits"
);

Self { bits, validity }
pub unsafe fn new_unchecked(bits: BitBuffer, validity: Mask) -> Self {
if cfg!(debug_assertions) {
Self::new(bits, validity)
} else {
Self { bits, validity }
}
}

/// Decomposes the boolean vector into its constituent parts.
/// Decomposes the boolean vector into its constituent parts (bit buffer and validity).
pub fn into_parts(self) -> (BitBuffer, Mask) {
(self.bits, self.validity)
}
Expand Down
19 changes: 8 additions & 11 deletions vortex-vector/src/bool/vector_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl BoolVectorMut {
///
/// Panics if the length of the validity mask does not match the length of the bits.
pub fn new(bits: BitBufferMut, validity: MaskMut) -> Self {
Self::try_new(bits, validity)
.vortex_expect("`BoolVector` validity mask must have the same length as bits")
Self::try_new(bits, validity).vortex_expect("Failed to create `BoolVectorMut`")
}

/// Tries to create a new [`BoolVectorMut`] from the given bits and validity mask.
Expand All @@ -104,13 +103,11 @@ impl BoolVectorMut {
/// Ideally, they are taken from `into_parts`, mutated in a way that doesn't re-allocate, and
/// then passed back to this function.
pub unsafe fn new_unchecked(bits: BitBufferMut, validity: MaskMut) -> Self {
debug_assert_eq!(
bits.len(),
validity.len(),
"`BoolVector` validity mask must have the same length as bits"
);

Self { bits, validity }
if cfg!(debug_assertions) {
Self::new(bits, validity)
} else {
Self { bits, validity }
}
}

/// Creates a new mutable boolean vector with the given `capacity`.
Expand All @@ -121,7 +118,7 @@ impl BoolVectorMut {
}
}

/// Returns the parts of the mutable vector.
/// Decomposes the boolean vector into its constituent parts (bit buffer and validity).
pub fn into_parts(self) -> (BitBufferMut, MaskMut) {
(self.bits, self.validity)
}
Expand Down Expand Up @@ -151,7 +148,7 @@ impl VectorMutOps for BoolVectorMut {
}

fn append_nulls(&mut self, n: usize) {
self.bits.append_n(false, n);
self.bits.append_n(false, n); // Note that the value we push doesn't actually matter.
self.validity.append_n(false, n);
}

Expand Down
17 changes: 11 additions & 6 deletions vortex-vector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
#![deny(clippy::missing_safety_doc)]

mod bool;
mod macros;
mod null;
mod ops;
mod primitive;
mod private;
mod vector;
mod vector_mut;
mod struct_;

pub use bool::{BoolVector, BoolVectorMut};
pub use null::{NullVector, NullVectorMut};
pub use ops::{VectorMutOps, VectorOps};
pub use primitive::{PVector, PVectorMut, PrimitiveVector, PrimitiveVectorMut};
pub use struct_::{StructVector, StructVectorMut};

mod ops;
mod vector;
mod vector_mut;

pub use ops::{VectorMutOps, VectorOps};
pub use vector::Vector;
pub use vector_mut::VectorMut;

mod macros;
mod private;
8 changes: 8 additions & 0 deletions vortex-vector/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ macro_rules! match_each_vector {
let $vec = v;
$body
}
$crate::Vector::Struct(v) => {
let $vec = v;
$body
}
}
}};
}
Expand Down Expand Up @@ -98,6 +102,10 @@ macro_rules! match_each_vector_mut {
let $vec = v;
$body
}
$crate::VectorMut::Struct(v) => {
let $vec = v;
$body
}
}
}};
}
Expand Down
5 changes: 5 additions & 0 deletions vortex-vector/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ pub trait VectorMutOps: private::Sealed + Into<VectorMut> {
fn reserve(&mut self, additional: usize);

/// Extends the vector by appending elements from another vector.
///
/// # Panics
///
/// Panics if the `other` vector has the wrong type (for example, a
/// [`StructVector`](crate::StructVector) might have incorrect fields).
fn extend_from_vector(&mut self, other: &Self::Immutable);

/// Appends `n` null elements to the vector.
Expand Down
19 changes: 8 additions & 11 deletions vortex-vector/src/primitive/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ impl<T: NativePType> PVector<T> {
///
/// Panics if the length of the validity mask does not match the length of the elements buffer.
pub fn new(elements: Buffer<T>, validity: Mask) -> Self {
Self::try_new(elements, validity)
.vortex_expect("`PVector` validity mask must have the same length as elements")
Self::try_new(elements, validity).vortex_expect("Failed to create `PVector`")
}

/// Tries to create a new [`PVector<T>`] from the given elements buffer and validity mask.
Expand All @@ -59,17 +58,15 @@ impl<T: NativePType> PVector<T> {
/// # Safety
///
/// The caller must ensure that the validity mask has the same length as the elements buffer.
pub fn new_unchecked(elements: Buffer<T>, validity: Mask) -> Self {
debug_assert_eq!(
validity.len(),
elements.len(),
"`PVector` validity mask must have the same length as elements"
);

Self { elements, validity }
pub unsafe fn new_unchecked(elements: Buffer<T>, validity: Mask) -> Self {
if cfg!(debug_assertions) {
Self::new(elements, validity)
} else {
Self { elements, validity }
}
}

/// Decomposes the primitive vector into its constituent parts.
/// Decomposes the primitive vector into its constituent parts (buffer and validity).
pub fn into_parts(self) -> (Buffer<T>, Mask) {
(self.elements, self.validity)
}
Expand Down
19 changes: 8 additions & 11 deletions vortex-vector/src/primitive/generic_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ impl<T> PVectorMut<T> {
///
/// Panics if the length of the validity mask does not match the length of the elements buffer.
pub fn new(elements: BufferMut<T>, validity: MaskMut) -> Self {
Self::try_new(elements, validity)
.vortex_expect("`PVectorMut` validity mask must have the same length as elements")
Self::try_new(elements, validity).vortex_expect("Failed to create `PVectorMut`")
}

/// Tries to create a new [`PVectorMut<T>`] from the given elements buffer and validity mask.
Expand Down Expand Up @@ -143,13 +142,11 @@ impl<T> PVectorMut<T> {
/// Ideally, they are taken from `into_parts`, mutated in a way that doesn't re-allocate, and
/// then passed back to this function.
pub unsafe fn new_unchecked(elements: BufferMut<T>, validity: MaskMut) -> Self {
debug_assert_eq!(
elements.len(),
validity.len(),
"`PVectorMut` validity mask must have the same length as elements"
);

Self { elements, validity }
if cfg!(debug_assertions) {
Self::new(elements, validity)
} else {
Self { elements, validity }
}
}

/// Create a new mutable primitive vector with the given capacity.
Expand All @@ -160,7 +157,7 @@ impl<T> PVectorMut<T> {
}
}

/// Decomposes the primitive vector into its constituent parts.
/// Decomposes the primitive vector into its constituent parts (buffer and validity).
pub fn into_parts(self) -> (BufferMut<T>, MaskMut) {
(self.elements, self.validity)
}
Expand Down Expand Up @@ -189,7 +186,7 @@ impl<T: NativePType> VectorMutOps for PVectorMut<T> {
}

fn append_nulls(&mut self, n: usize) {
self.elements.push_n(T::zero(), n);
self.elements.push_n(T::zero(), n); // Note that the value we push doesn't actually matter.
self.validity.append_n(false, n);
}

Expand Down
1 change: 1 addition & 0 deletions vortex-vector/src/primitive/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl<T: NativePType> FromIterator<T> for PVectorMut<T> {
///
/// It consumes the mutable vector and iterates over the elements, yielding `None` for null values
/// and `Some(value)` for valid values.
#[derive(Debug)]
pub struct PVectorMutIterator<T: NativePType> {
/// The vector being iterated over.
vector: PVectorMut<T>,
Expand Down
3 changes: 3 additions & 0 deletions vortex-vector/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ impl Sealed for PrimitiveVector {}
impl Sealed for PrimitiveVectorMut {}
impl<T: NativePType> Sealed for PVector<T> {}
impl<T: NativePType> Sealed for PVectorMut<T> {}

impl Sealed for StructVector {}
impl Sealed for StructVectorMut {}
24 changes: 24 additions & 0 deletions vortex-vector/src/struct_/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! Definition and implementation of [`StructVector`] and [`StructVectorMut`].

mod vector;
pub use vector::StructVector;

mod vector_mut;
pub use vector_mut::StructVectorMut;

use crate::{Vector, VectorMut};

impl From<StructVector> for Vector {
fn from(v: StructVector) -> Self {
Self::Struct(v)
}
}

impl From<StructVectorMut> for VectorMut {
fn from(v: StructVectorMut) -> Self {
Self::Struct(v)
}
}
Loading
Loading