Skip to content

Commit b5f46d3

Browse files
committed
add StructVector stubs
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 5de123a commit b5f46d3

File tree

8 files changed

+242
-19
lines changed

8 files changed

+242
-19
lines changed

vortex-vector/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@
1212
#![deny(clippy::missing_safety_doc)]
1313

1414
mod bool;
15-
mod macros;
1615
mod null;
17-
mod ops;
1816
mod primitive;
19-
mod private;
20-
mod vector;
21-
mod vector_mut;
17+
mod struct_;
2218

2319
pub use bool::{BoolVector, BoolVectorMut};
2420
pub use null::{NullVector, NullVectorMut};
25-
pub use ops::{VectorMutOps, VectorOps};
2621
pub use primitive::{PVec, PVecMut, PrimitiveVector, PrimitiveVectorMut};
22+
pub use struct_::{StructVector, StructVectorMut};
23+
24+
mod ops;
25+
mod vector;
26+
mod vector_mut;
27+
28+
pub use ops::{VectorMutOps, VectorOps};
2729
pub use vector::Vector;
2830
pub use vector_mut::VectorMut;
31+
32+
mod macros;
33+
mod private;

vortex-vector/src/macros.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ macro_rules! match_each_vector {
4848
let $vec = v;
4949
$body
5050
}
51+
$crate::Vector::Struct(v) => {
52+
let $vec = v;
53+
$body
54+
}
5155
}
5256
}};
5357
}
@@ -98,6 +102,10 @@ macro_rules! match_each_vector_mut {
98102
let $vec = v;
99103
$body
100104
}
105+
$crate::VectorMut::Struct(v) => {
106+
let $vec = v;
107+
$body
108+
}
101109
}
102110
}};
103111
}

vortex-vector/src/private.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ impl Sealed for PrimitiveVector {}
2828
impl Sealed for PrimitiveVectorMut {}
2929
impl<T: NativePType> Sealed for PVec<T> {}
3030
impl<T: NativePType> Sealed for PVecMut<T> {}
31+
32+
impl Sealed for StructVector {}
33+
impl Sealed for StructVectorMut {}

vortex-vector/src/struct_/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Definition and implementation of [`StructVector`] and [`StructVectorMut`].
5+
6+
mod vector;
7+
pub use vector::StructVector;
8+
9+
mod vector_mut;
10+
pub use vector_mut::StructVectorMut;
11+
12+
use crate::{Vector, VectorMut};
13+
14+
impl From<StructVector> for Vector {
15+
fn from(v: StructVector) -> Self {
16+
Self::Struct(v)
17+
}
18+
}
19+
20+
impl From<StructVectorMut> for VectorMut {
21+
fn from(v: StructVectorMut) -> Self {
22+
Self::Struct(v)
23+
}
24+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Definition and implementation of [`StructVector`].
5+
6+
use vortex_mask::Mask;
7+
8+
use crate::{StructVectorMut, VectorOps};
9+
10+
/// An immutable vector of boolean values.
11+
///
12+
/// `StructVector` can be considered a borrowed / frozen version of [`StructVectorMut`], which is
13+
/// created via the [`freeze`](crate::VectorMutOps::freeze) method.
14+
///
15+
/// See the documentation for [`StructVectorMut`] for more information.
16+
#[derive(Debug, Clone)]
17+
pub struct StructVector {
18+
/// The validity mask (where `true` represents an element is **not** null).
19+
pub(super) validity: Mask,
20+
}
21+
22+
impl VectorOps for StructVector {
23+
type Mutable = StructVectorMut;
24+
25+
fn len(&self) -> usize {
26+
todo!()
27+
}
28+
29+
fn validity(&self) -> &Mask {
30+
&self.validity
31+
}
32+
33+
fn try_into_mut(self) -> Result<Self::Mutable, Self>
34+
where
35+
Self: Sized,
36+
{
37+
todo!()
38+
}
39+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Definition and implementation of [`StructVectorMut`].
5+
6+
use vortex_mask::MaskMut;
7+
8+
use crate::{StructVector, VectorMutOps};
9+
10+
/// A mutable vector of struct values (values with named fields).
11+
///
12+
/// TODO docs.
13+
#[derive(Debug, Clone)]
14+
pub struct StructVectorMut {
15+
/// The validity mask (where `true` represents an element is **not** null).
16+
pub(super) _validity: MaskMut,
17+
}
18+
19+
impl StructVectorMut {
20+
/// Creates a new mutable boolean vector with the given `capacity`.
21+
pub fn with_capacity(_capacity: usize) -> Self {
22+
todo!()
23+
}
24+
}
25+
26+
impl VectorMutOps for StructVectorMut {
27+
type Immutable = StructVector;
28+
29+
fn len(&self) -> usize {
30+
todo!()
31+
}
32+
33+
fn capacity(&self) -> usize {
34+
todo!()
35+
}
36+
37+
fn reserve(&mut self, _additional: usize) {
38+
todo!()
39+
}
40+
41+
fn extend_from_vector(&mut self, _other: &StructVector) {
42+
todo!()
43+
}
44+
45+
fn append_nulls(&mut self, _n: usize) {
46+
todo!()
47+
}
48+
49+
fn freeze(self) -> Self::Immutable {
50+
todo!()
51+
}
52+
53+
fn split_off(&mut self, _at: usize) -> Self {
54+
todo!()
55+
}
56+
57+
fn unsplit(&mut self, _other: Self) {
58+
todo!()
59+
}
60+
}

vortex-vector/src/vector.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use vortex_error::vortex_panic;
1010

1111
use crate::macros::match_each_vector;
12-
use crate::{BoolVector, NullVector, PrimitiveVector, VectorMut, VectorOps};
12+
use crate::{BoolVector, NullVector, PrimitiveVector, StructVector, VectorMut, VectorOps};
1313

1414
/// An enum over all kinds of immutable vectors, which represent fully decompressed (canonical)
1515
/// array data.
@@ -41,8 +41,8 @@ pub enum Vector {
4141
// List(ListVector),
4242
// FixedList
4343
// FixedList(FixedListVector),
44-
// Struct
45-
// Struct(StructVector),
44+
/// Vectors of Struct elements.
45+
Struct(StructVector),
4646
// Extension
4747
// Extension(ExtensionVector),
4848
}
@@ -69,27 +69,67 @@ impl VectorOps for Vector {
6969
}
7070

7171
impl Vector {
72-
/// Consumes `self` and returns the inner `NullVector` if `self` is of that variant.
72+
/// Returns a reference to the inner [`NullVector`] if `self` is of that variant.
73+
pub fn as_null(&self) -> &NullVector {
74+
if let Vector::Null(v) = self {
75+
return v;
76+
}
77+
vortex_panic!("Expected NullVector, got {self:?}");
78+
}
79+
80+
/// Returns a reference to the inner [`BoolVector`] if `self` is of that variant.
81+
pub fn as_bool(&self) -> &BoolVector {
82+
if let Vector::Bool(v) = self {
83+
return v;
84+
}
85+
vortex_panic!("Expected BoolVector, got {self:?}");
86+
}
87+
88+
/// Returns a reference to the inner [`PrimitiveVector`] if `self` is of that variant.
89+
pub fn as_primitive(&self) -> &PrimitiveVector {
90+
if let Vector::Primitive(v) = self {
91+
return v;
92+
}
93+
vortex_panic!("Expected PrimitiveVector, got {self:?}");
94+
}
95+
96+
/// Returns a reference to the inner [`StructVector`] if `self` is of that variant.
97+
pub fn as_struct(&self) -> &StructVector {
98+
if let Vector::Struct(v) = self {
99+
return v;
100+
}
101+
vortex_panic!("Expected StructVector, got {self:?}");
102+
}
103+
104+
/// Consumes `self` and returns the inner [`NullVector`] if `self` is of that variant.
73105
pub fn into_null(self) -> NullVector {
74106
if let Vector::Null(v) = self {
75107
return v;
76108
}
77109
vortex_panic!("Expected NullVector, got {self:?}");
78110
}
79111

80-
/// Consumes `self` and returns the inner `BoolVector` if `self` is of that variant.
112+
/// Consumes `self` and returns the inner [`BoolVector`] if `self` is of that variant.
81113
pub fn into_bool(self) -> BoolVector {
82114
if let Vector::Bool(v) = self {
83115
return v;
84116
}
85117
vortex_panic!("Expected BoolVector, got {self:?}");
86118
}
87119

88-
/// Consumes `self` and returns the inner `PrimitiveVector` if `self` is of that variant.
120+
/// Consumes `self` and returns the inner [`PrimitiveVector`] if `self` is of that variant.
89121
pub fn into_primitive(self) -> PrimitiveVector {
90122
if let Vector::Primitive(v) = self {
91123
return v;
92124
}
93125
vortex_panic!("Expected PrimitiveVector, got {self:?}");
94126
}
127+
128+
/// Consumes `self` and returns the inner [`StructVector`] if `self` is of that variant.
129+
pub fn into_struct(self) -> StructVector {
130+
if let Vector::Struct(v) = self {
131+
return v;
132+
}
133+
vortex_panic!("Expected StructVector, got {self:?}");
134+
}
95135
}

vortex-vector/src/vector_mut.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use vortex_dtype::DType;
1010
use vortex_error::vortex_panic;
1111

1212
use super::macros::match_each_vector_mut;
13-
use crate::{BoolVectorMut, NullVectorMut, PrimitiveVectorMut, Vector, VectorMutOps};
13+
use crate::{
14+
BoolVectorMut, NullVectorMut, PrimitiveVectorMut, StructVectorMut, Vector, VectorMutOps,
15+
};
1416

1517
/// An enum over all kinds of mutable vectors, which represent fully decompressed (canonical) array
1618
/// data.
@@ -23,15 +25,17 @@ use crate::{BoolVectorMut, NullVectorMut, PrimitiveVectorMut, Vector, VectorMutO
2325
/// [`VectorOps`](crate::VectorOps) trait.
2426
#[derive(Debug, Clone)]
2527
pub enum VectorMut {
26-
/// Null mutable vectors.
28+
/// Mutable Null vectors.
2729
Null(NullVectorMut),
28-
/// Boolean mutable vectors.
30+
/// Mutable Boolean vectors.
2931
Bool(BoolVectorMut),
30-
/// Primitive mutable vectors.
32+
/// Mutable Primitive vectors.
3133
///
3234
/// Note that [`PrimitiveVectorMut`] is an enum over the different possible (generic)
3335
/// [`PVecMut<T>`](crate::PVecMut)s. See the documentation for more information.
3436
Primitive(PrimitiveVectorMut),
37+
/// Mutable vectors of Struct elements.
38+
Struct(StructVectorMut),
3539
}
3640

3741
impl VectorMut {
@@ -95,29 +99,69 @@ impl VectorMutOps for VectorMut {
9599
}
96100

97101
impl VectorMut {
98-
/// Convert into NullVectorMut, panicking if the type does not match.
102+
/// Returns a reference to the inner [`NullVectorMut`] if `self` is of that variant.
103+
pub fn as_null(&self) -> &NullVectorMut {
104+
if let VectorMut::Null(v) = self {
105+
return v;
106+
}
107+
vortex_panic!("Expected NullVectorMut, got {self:?}");
108+
}
109+
110+
/// Returns a reference to the inner [`BoolVectorMut`] if `self` is of that variant.
111+
pub fn as_bool(&self) -> &BoolVectorMut {
112+
if let VectorMut::Bool(v) = self {
113+
return v;
114+
}
115+
vortex_panic!("Expected BoolVectorMut, got {self:?}");
116+
}
117+
118+
/// Returns a reference to the inner [`PrimitiveVectorMut`] if `self` is of that variant.
119+
pub fn as_primitive(&self) -> &PrimitiveVectorMut {
120+
if let VectorMut::Primitive(v) = self {
121+
return v;
122+
}
123+
vortex_panic!("Expected PrimitiveVectorMut, got {self:?}");
124+
}
125+
126+
/// Returns a reference to the inner [`StructVectorMut`] if `self` is of that variant.
127+
pub fn as_struct(&self) -> &StructVectorMut {
128+
if let VectorMut::Struct(v) = self {
129+
return v;
130+
}
131+
vortex_panic!("Expected StructVectorMut, got {self:?}");
132+
}
133+
134+
/// Consumes `self` and returns the inner [`NullVectorMut`] if `self` is of that variant.
99135
pub fn into_null(self) -> NullVectorMut {
100136
if let VectorMut::Null(v) = self {
101137
return v;
102138
}
103139
vortex_panic!("Expected NullVectorMut, got {self:?}");
104140
}
105141

106-
/// Convert into BoolVectorMut, panicking if the type does not match.
142+
/// Consumes `self` and returns the inner [`BoolVectorMut`] if `self` is of that variant.
107143
pub fn into_bool(self) -> BoolVectorMut {
108144
if let VectorMut::Bool(v) = self {
109145
return v;
110146
}
111147
vortex_panic!("Expected BoolVectorMut, got {self:?}");
112148
}
113149

114-
/// Convert into PrimitiveVectorMut, panicking if the type does not match.
150+
/// Consumes `self` and returns the inner [`PrimitiveVectorMut`] if `self` is of that variant.
115151
pub fn into_primitive(self) -> PrimitiveVectorMut {
116152
if let VectorMut::Primitive(v) = self {
117153
return v;
118154
}
119155
vortex_panic!("Expected PrimitiveVectorMut, got {self:?}");
120156
}
157+
158+
/// Consumes `self` and returns the inner [`StructVectorMut`] if `self` is of that variant.
159+
pub fn into_struct(self) -> StructVectorMut {
160+
if let VectorMut::Struct(v) = self {
161+
return v;
162+
}
163+
vortex_panic!("Expected StructVectorMut, got {self:?}");
164+
}
121165
}
122166

123167
#[cfg(test)]

0 commit comments

Comments
 (0)