Skip to content

Commit 4fc1c05

Browse files
committed
VarBinVector
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 871ab1b commit 4fc1c05

File tree

9 files changed

+119
-96
lines changed

9 files changed

+119
-96
lines changed

vortex-compute/src/mask/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::ops::BitAnd;
88
use vortex_dtype::NativePType;
99
use vortex_mask::Mask;
1010
use vortex_vector::{
11-
BoolVector, NullVector, PrimitiveVector, StructVector, Vector, match_each_pvector,
12-
match_each_vector,
11+
BoolVector, NullVector, PVector, PrimitiveVector, StructVector, VarBinType, VarBinVector,
12+
Vector, match_each_pvector, match_each_vector,
1313
};
1414

1515
/// Trait for masking the validity of an array or vector.
@@ -37,7 +37,8 @@ impl MaskValidity for NullVector {
3737
impl MaskValidity for BoolVector {
3838
fn mask_validity(self, mask: &Mask) -> Self {
3939
let (bits, validity) = self.into_parts();
40-
Self::new(bits, validity.bitand(mask))
40+
// SAFETY: we are preserving the original bits buffer and only modifying the validity.
41+
unsafe { Self::new_unchecked(bits, validity.bitand(mask)) }
4142
}
4243
}
4344

@@ -47,16 +48,26 @@ impl MaskValidity for PrimitiveVector {
4748
}
4849
}
4950

50-
impl<T: NativePType> MaskValidity for vortex_vector::PVector<T> {
51+
impl<T: NativePType> MaskValidity for PVector<T> {
5152
fn mask_validity(self, mask: &Mask) -> Self {
5253
let (data, validity) = self.into_parts();
53-
Self::new(data, validity.bitand(mask))
54+
// SAFETY: we are preserving the original data buffer and only modifying the validity.
55+
unsafe { Self::new_unchecked(data, validity.bitand(mask)) }
56+
}
57+
}
58+
59+
impl<T: VarBinType> MaskValidity for VarBinVector<T> {
60+
fn mask_validity(self, mask: &Mask) -> Self {
61+
let (views, buffers, validity) = self.into_parts();
62+
// SAFETY: we are preserving the original views and buffers, only modifying the validity.
63+
unsafe { Self::new_unchecked(views, buffers, validity.bitand(mask)) }
5464
}
5565
}
5666

5767
impl MaskValidity for StructVector {
5868
fn mask_validity(self, mask: &Mask) -> Self {
5969
let (fields, validity) = self.into_parts();
60-
StructVector::new(fields, validity.bitand(mask))
70+
// SAFETY: we are preserving the original fields and only modifying the validity.
71+
unsafe { StructVector::new_unchecked(fields, validity.bitand(mask)) }
6172
}
6273
}

vortex-vector/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! Immutable and mutable decompressed (canonical) vectors for Vortex.
77
88
#![deny(missing_docs)]
9-
#![deny(clippy::missing_docs_in_private_items)]
109
#![deny(clippy::missing_errors_doc)]
1110
#![deny(clippy::missing_panics_doc)]
1211
#![deny(clippy::missing_safety_doc)]

vortex-vector/src/varbin/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl VarBinTypeDowncast for Vector {
2929
if let Vector::Binary(v) = self {
3030
return v;
3131
}
32-
3332
vortex_panic!("Expected BinaryVector, got {self:?}");
3433
}
3534

vortex-vector/src/varbin/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
//! Variable-length binary types and related traits.
5+
46
use std::fmt::Debug;
57

68
use crate::{VarBinVector, VarBinVectorMut, Vector, VectorMut};
@@ -81,8 +83,11 @@ pub trait VarBinTypeUpcast {
8183
fn from_string(input: Self::Input<StringType>) -> Self;
8284
}
8385

86+
/// Private module to seal the [`VarBinType`] trait.
8487
mod private {
88+
/// Sealed trait to prevent external implementations of [`VarBinType`].
8589
pub trait Sealed {}
90+
8691
impl Sealed for super::StringType {}
8792
impl Sealed for super::BinaryType {}
8893
}

vortex-vector/src/varbin/vector.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
//! Variable-length binary vector implementation.
5+
46
use std::sync::Arc;
57

68
use vortex_buffer::{Buffer, ByteBuffer};
@@ -14,9 +16,13 @@ use crate::varbin::view::BinaryView;
1416
/// A variable-length binary vector.
1517
#[derive(Debug, Clone)]
1618
pub struct VarBinVector<T: VarBinType> {
19+
/// Views into the binary data.
1720
views: Buffer<BinaryView>,
18-
validity: Mask,
21+
/// Buffers holding the referenced binary data.
1922
buffers: Arc<Box<[ByteBuffer]>>,
23+
/// Validity mask for the vector.
24+
validity: Mask,
25+
/// Marker trait for the [`VarBinType`].
2026
_marker: std::marker::PhantomData<T>,
2127
}
2228

@@ -33,16 +39,21 @@ impl<T: VarBinType> VarBinVector<T> {
3339
/// - The `views` buffer correctly references the data in the `buffers`.
3440
pub unsafe fn new_unchecked(
3541
views: Buffer<BinaryView>,
36-
validity: Mask,
3742
buffers: Arc<Box<[ByteBuffer]>>,
43+
validity: Mask,
3844
) -> Self {
3945
Self {
4046
views,
41-
validity,
4247
buffers,
48+
validity,
4349
_marker: std::marker::PhantomData,
4450
}
4551
}
52+
53+
/// Decomposes the vector into its constituent parts.
54+
pub fn into_parts(self) -> (Buffer<BinaryView>, Arc<Box<[ByteBuffer]>>, Mask) {
55+
(self.views, self.buffers, self.validity)
56+
}
4657
}
4758

4859
impl<T: VarBinType> VectorOps for VarBinVector<T> {
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex_buffer::{BufferMut, ByteBuffer};
4+
//! Mutable variable-length binary vector.
5+
6+
use vortex_buffer::{BufferMut, ByteBuffer, ByteBufferMut};
57
use vortex_mask::MaskMut;
68

79
use crate::VectorMutOps;
@@ -10,33 +12,23 @@ use crate::varbin::vector::VarBinVector;
1012
use crate::varbin::view::BinaryView;
1113

1214
/// Mutable variable-length binary vector.
15+
#[allow(dead_code)] // FIXME(ngates): remove after implementing the methods
1316
#[derive(Clone, Debug)]
1417
pub struct VarBinVectorMut<T: VarBinType> {
18+
/// Views into the binary data.
1519
views: BufferMut<BinaryView>,
20+
/// Validity mask for the vector.
1621
validity: MaskMut,
1722

23+
/// The completed buffers holding referenced binary data.
1824
buffers: Vec<ByteBuffer>,
19-
open_buffer: Option<ByteBuffer>,
25+
/// The current buffer being appended to, if any.
26+
open_buffer: Option<ByteBufferMut>,
2027

28+
/// Marker trait for the [`VarBinType`].
2129
_marker: std::marker::PhantomData<T>,
2230
}
2331

24-
impl<T: VarBinType> VarBinVectorMut<T> {
25-
pub(super) fn new(
26-
views: BufferMut<BinaryView>,
27-
validity: MaskMut,
28-
buffers: Vec<ByteBuffer>,
29-
) -> Self {
30-
Self {
31-
views,
32-
validity,
33-
buffers,
34-
open_buffer: None,
35-
_marker: std::marker::PhantomData,
36-
}
37-
}
38-
}
39-
4032
impl<T: VarBinType> VectorMutOps for VarBinVectorMut<T> {
4133
type Immutable = VarBinVector<T>;
4234

@@ -52,7 +44,7 @@ impl<T: VarBinType> VectorMutOps for VarBinVectorMut<T> {
5244
self.views.reserve(additional);
5345
}
5446

55-
fn extend_from_vector(&mut self, other: &Self::Immutable) {
47+
fn extend_from_vector(&mut self, _other: &Self::Immutable) {
5648
todo!()
5749
}
5850

@@ -65,11 +57,11 @@ impl<T: VarBinType> VectorMutOps for VarBinVectorMut<T> {
6557
todo!()
6658
}
6759

68-
fn split_off(&mut self, at: usize) -> Self {
60+
fn split_off(&mut self, _at: usize) -> Self {
6961
todo!()
7062
}
7163

72-
fn unsplit(&mut self, other: Self) {
64+
fn unsplit(&mut self, _other: Self) {
7365
todo!()
7466
}
7567
}

0 commit comments

Comments
 (0)