Skip to content

Commit 8ec8fa9

Browse files
committed
set up scaffolding for FixedSizeListVector
Signed-off-by: Connor Tsui <[email protected]>
1 parent cee7469 commit 8ec8fa9

File tree

10 files changed

+166
-5
lines changed

10 files changed

+166
-5
lines changed

vortex-compute/src/mask/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use std::ops::BitAnd;
88
use vortex_dtype::{NativeDecimalType, NativePType};
99
use vortex_mask::Mask;
1010
use vortex_vector::{
11-
BoolVector, DVector, DecimalVector, NullVector, PVector, PrimitiveVector, StructVector,
12-
VarBinType, VarBinVector, Vector, match_each_dvector, match_each_pvector, match_each_vector,
11+
BoolVector, DVector, DecimalVector, FixedSizeListVector, NullVector, PVector, PrimitiveVector,
12+
StructVector, VarBinType, VarBinVector, Vector, match_each_dvector, match_each_pvector,
13+
match_each_vector,
1314
};
1415

1516
/// Trait for masking the validity of an array or vector.
@@ -78,6 +79,12 @@ impl<T: VarBinType> MaskValidity for VarBinVector<T> {
7879
}
7980
}
8081

82+
impl MaskValidity for FixedSizeListVector {
83+
fn mask_validity(self, _mask: &Mask) -> Self {
84+
todo!()
85+
}
86+
}
87+
8188
impl MaskValidity for StructVector {
8289
fn mask_validity(self, mask: &Mask) -> Self {
8390
let (fields, validity) = self.into_parts();
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 [`FixedSizeListVector`] and [`FixedSizeListVectorMut`].
5+
6+
mod vector;
7+
pub use vector::FixedSizeListVector;
8+
9+
mod vector_mut;
10+
pub use vector_mut::FixedSizeListVectorMut;
11+
12+
use crate::{Vector, VectorMut};
13+
14+
impl From<FixedSizeListVector> for Vector {
15+
fn from(v: FixedSizeListVector) -> Self {
16+
Self::FixedSizeList(v)
17+
}
18+
}
19+
20+
impl From<FixedSizeListVectorMut> for VectorMut {
21+
fn from(v: FixedSizeListVectorMut) -> Self {
22+
Self::FixedSizeList(v)
23+
}
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Definition and implementation of [`FixedSizeListVector`].
5+
6+
use crate::{FixedSizeListVectorMut, VectorOps};
7+
8+
/// An immutable vector of fixed-size lists.
9+
///
10+
/// `FixedSizeListVector` can be considered a borrowed / frozen version of
11+
/// [`FixedSizeListVectorMut`], which is created via the [`freeze`](crate::VectorMutOps::freeze)
12+
/// method.
13+
///
14+
/// See the documentation for [`FixedSizeListVectorMut`] for more information.
15+
#[derive(Debug, Clone)]
16+
pub struct FixedSizeListVector;
17+
18+
impl VectorOps for FixedSizeListVector {
19+
type Mutable = FixedSizeListVectorMut;
20+
21+
fn len(&self) -> usize {
22+
todo!()
23+
}
24+
25+
fn validity(&self) -> &vortex_mask::Mask {
26+
todo!()
27+
}
28+
29+
fn try_into_mut(self) -> Result<Self::Mutable, Self>
30+
where
31+
Self: Sized,
32+
{
33+
todo!()
34+
}
35+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Definition and implementation of [`FixedSizeListVectorMut`].
5+
6+
use crate::{FixedSizeListVector, VectorMutOps};
7+
8+
/// TODO docs.
9+
#[derive(Debug, Clone)]
10+
pub struct FixedSizeListVectorMut;
11+
12+
impl VectorMutOps for FixedSizeListVectorMut {
13+
type Immutable = FixedSizeListVector;
14+
15+
fn len(&self) -> usize {
16+
todo!()
17+
}
18+
19+
fn capacity(&self) -> usize {
20+
todo!()
21+
}
22+
23+
fn reserve(&mut self, _additional: usize) {
24+
todo!()
25+
}
26+
27+
fn extend_from_vector(&mut self, _other: &Self::Immutable) {
28+
todo!()
29+
}
30+
31+
fn append_nulls(&mut self, _n: usize) {
32+
todo!()
33+
}
34+
35+
fn freeze(self) -> Self::Immutable {
36+
todo!()
37+
}
38+
39+
fn split_off(&mut self, _at: usize) -> Self {
40+
todo!()
41+
}
42+
43+
fn unsplit(&mut self, _other: Self) {
44+
todo!()
45+
}
46+
}

vortex-vector/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
mod bool;
1414
mod decimal;
15+
mod fixed_size_list;
1516
mod null;
1617
mod primitive;
1718
mod struct_;
1819
mod varbin;
1920

2021
pub use bool::*;
2122
pub use decimal::*;
23+
pub use fixed_size_list::*;
2224
pub use null::*;
2325
pub use primitive::*;
2426
pub use struct_::*;

vortex-vector/src/macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ macro_rules! match_each_vector {
4545
$crate::Vector::Primitive($vec) => $body,
4646
$crate::Vector::String($vec) => $body,
4747
$crate::Vector::Binary($vec) => $body,
48+
$crate::Vector::FixedSizeList($vec) => $body,
4849
$crate::Vector::Struct($vec) => $body,
4950
}
5051
}};
@@ -91,6 +92,7 @@ macro_rules! match_each_vector_mut {
9192
$crate::VectorMut::Primitive($vec) => $body,
9293
$crate::VectorMut::String($vec) => $body,
9394
$crate::VectorMut::Binary($vec) => $body,
95+
$crate::VectorMut::FixedSizeList($vec) => $body,
9496
$crate::VectorMut::Struct($vec) => $body,
9597
}
9698
}};
@@ -115,6 +117,9 @@ macro_rules! __match_vector_pair_arms {
115117
($crate::$enum_left::Primitive($a), $crate::$enum_right::Primitive($b)) => $body,
116118
($crate::$enum_left::String($a), $crate::$enum_right::String($b)) => $body,
117119
($crate::$enum_left::Binary($a), $crate::$enum_right::Binary($b)) => $body,
120+
($crate::$enum_left::FixedSizeList($a), $crate::$enum_right::FixedSizeList($b)) => {
121+
$body
122+
}
118123
($crate::$enum_left::Struct($a), $crate::$enum_right::Struct($b)) => $body,
119124
_ => ::vortex_error::vortex_panic!("Mismatched vector types"),
120125
}

vortex-vector/src/private.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ impl<T: NativePType> Sealed for PVectorMut<T> {}
3737
impl<T: VarBinType> Sealed for VarBinVector<T> {}
3838
impl<T: VarBinType> Sealed for VarBinVectorMut<T> {}
3939

40+
impl Sealed for FixedSizeListVector {}
41+
impl Sealed for FixedSizeListVectorMut {}
42+
4043
impl Sealed for StructVector {}
4144
impl Sealed for StructVectorMut {}

vortex-vector/src/varbin/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub trait VarBinTypeUpcast {
8585

8686
/// Private module to seal the [`VarBinType`] trait.
8787
mod private {
88-
/// Sealed trait to prevent external implementations of [`VarBinType`].
88+
/// Sealed trait to prevent external implementations of [`VarBinType`](super::VarBinType).
8989
pub trait Sealed {}
9090

9191
impl Sealed for super::StringType {}

vortex-vector/src/vector.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
use vortex_error::vortex_panic;
1010

11+
use crate::fixed_size_list::FixedSizeListVector;
1112
use crate::{
1213
BinaryVector, BoolVector, DecimalVector, NullVector, PrimitiveVector, StringVector,
1314
StructVector, VectorMut, VectorOps, match_each_vector,
@@ -41,8 +42,8 @@ pub enum Vector {
4142
Binary(BinaryVector),
4243
// List
4344
// List(ListVector),
44-
// FixedList
45-
// FixedList(FixedListVector),
45+
/// Vectors of Lists with fixed sizes.
46+
FixedSizeList(FixedSizeListVector),
4647
/// Vectors of Struct elements.
4748
Struct(StructVector),
4849
}
@@ -109,6 +110,14 @@ impl Vector {
109110
vortex_panic!("Expected BinaryVector, got {self:?}");
110111
}
111112

113+
/// Returns a reference to the inner [`FixedSizeListVector`] if `self` is of that variant.
114+
pub fn as_fixed_size_list(&self) -> &FixedSizeListVector {
115+
if let Vector::FixedSizeList(v) = self {
116+
return v;
117+
}
118+
vortex_panic!("Expected FixedSizeListVector, got {self:?}");
119+
}
120+
112121
/// Returns a reference to the inner [`StructVector`] if `self` is of that variant.
113122
pub fn as_struct(&self) -> &StructVector {
114123
if let Vector::Struct(v) = self {
@@ -159,6 +168,15 @@ impl Vector {
159168
vortex_panic!("Expected BinaryVector, got {self:?}");
160169
}
161170

171+
/// Consumes `self` and returns the inner [`FixedSizeListVector`] if `self` is of that
172+
/// variant.
173+
pub fn into_fixed_size_list(self) -> FixedSizeListVector {
174+
if let Vector::FixedSizeList(v) = self {
175+
return v;
176+
}
177+
vortex_panic!("Expected FixedSizeListVector, got {self:?}");
178+
}
179+
162180
/// Consumes `self` and returns the inner [`StructVector`] if `self` is of that variant.
163181
pub fn into_struct(self) -> StructVector {
164182
if let Vector::Struct(v) = self {

vortex-vector/src/vector_mut.rs

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

12+
use crate::fixed_size_list::FixedSizeListVectorMut;
1213
use crate::varbin::{BinaryVectorMut, StringVectorMut};
1314
use crate::{
1415
BoolVectorMut, DecimalVectorMut, NullVectorMut, PrimitiveVectorMut, StructVectorMut, Vector,
@@ -41,6 +42,8 @@ pub enum VectorMut {
4142
String(StringVectorMut),
4243
/// Mutable Binary vectors.
4344
Binary(BinaryVectorMut),
45+
/// Mutable vectors of Lists with fixed sizes.
46+
FixedSizeList(FixedSizeListVectorMut),
4447
/// Mutable vectors of Struct elements.
4548
Struct(StructVectorMut),
4649
}
@@ -54,6 +57,7 @@ impl VectorMut {
5457
DType::Primitive(ptype, _) => {
5558
PrimitiveVectorMut::with_capacity(*ptype, capacity).into()
5659
}
60+
DType::FixedSizeList(..) => todo!("TODO(connor)"),
5761
DType::Struct(struct_fields, _) => {
5862
StructVectorMut::with_capacity(struct_fields, capacity).into()
5963
}
@@ -146,6 +150,14 @@ impl VectorMut {
146150
vortex_panic!("Expected BinaryVectorMut, got {self:?}");
147151
}
148152

153+
/// Returns a reference to the inner [`FixedSizeListVectorMut`] if `self` is of that variant.
154+
pub fn as_fixed_size_list(&self) -> &FixedSizeListVectorMut {
155+
if let VectorMut::FixedSizeList(v) = self {
156+
return v;
157+
}
158+
vortex_panic!("Expected FixedSizeListVectorMut, got {self:?}");
159+
}
160+
149161
/// Returns a reference to the inner [`StructVectorMut`] if `self` is of that variant.
150162
pub fn as_struct(&self) -> &StructVectorMut {
151163
if let VectorMut::Struct(v) = self {
@@ -196,6 +208,15 @@ impl VectorMut {
196208
vortex_panic!("Expected BinaryVectorMut, got {self:?}");
197209
}
198210

211+
/// Consumes `self` and returns the inner [`FixedSizeListVectorMut`] if `self` is of that
212+
/// variant.
213+
pub fn into_fixed_size_list(self) -> FixedSizeListVectorMut {
214+
if let VectorMut::FixedSizeList(v) = self {
215+
return v;
216+
}
217+
vortex_panic!("Expected FixedSizeListVectorMut, got {self:?}");
218+
}
219+
199220
/// Consumes `self` and returns the inner [`StructVectorMut`] if `self` is of that variant.
200221
pub fn into_struct(self) -> StructVectorMut {
201222
if let VectorMut::Struct(v) = self {

0 commit comments

Comments
 (0)