Skip to content

Commit f778720

Browse files
committed
Decimal Vector
Signed-off-by: Nicholas Gates <[email protected]>
2 parents 156cdca + 1cb3f21 commit f778720

File tree

11 files changed

+163
-179
lines changed

11 files changed

+163
-179
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vortex-python/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ arrow-data = { workspace = true }
2727
arrow-schema = { workspace = true }
2828
itertools = { workspace = true }
2929
log = { workspace = true }
30-
mimalloc = { workspace = true }
3130
object_store = { workspace = true, features = ["aws", "gcp", "azure", "http"] }
3231
parking_lot = { workspace = true }
3332
pyo3 = { workspace = true, features = ["abi3", "abi3-py311"] }

vortex-python/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ use tokio::runtime::Runtime;
2929
use vortex::error::{VortexError, VortexExpect as _};
3030
use vortex::io::runtime::tokio::TokioRuntime;
3131

32-
#[global_allocator]
33-
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
34-
3532
static TOKIO_RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
3633
Runtime::new()
3734
.map_err(VortexError::from)

vortex-vector/src/macros.rs

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ macro_rules! match_each_vector {
5050
}};
5151
}
5252

53-
pub(crate) use match_each_vector;
54-
5553
/// Matches on all variants of [`VectorMut`] and executes the same code for each variant branch.
5654
///
5755
/// This macro eliminates repetitive match statements when implementing operations that need to work
@@ -98,4 +96,86 @@ macro_rules! match_each_vector_mut {
9896
}};
9997
}
10098

101-
pub(crate) use match_each_vector_mut;
99+
/// Internal macro to generate match arms for vector pairs.
100+
#[doc(hidden)]
101+
#[macro_export]
102+
macro_rules! __match_vector_pair_arms {
103+
(
104+
$left:expr,
105+
$right:expr,
106+
$enum_left:ident,
107+
$enum_right:ident,
108+
$a:ident,
109+
$b:ident,
110+
$body:expr
111+
) => {{
112+
match ($left, $right) {
113+
($crate::$enum_left::Null($a), $crate::$enum_right::Null($b)) => $body,
114+
($crate::$enum_left::Bool($a), $crate::$enum_right::Bool($b)) => $body,
115+
($crate::$enum_left::Primitive($a), $crate::$enum_right::Primitive($b)) => $body,
116+
($crate::$enum_left::String($a), $crate::$enum_right::String($b)) => $body,
117+
($crate::$enum_left::Binary($a), $crate::$enum_right::Binary($b)) => $body,
118+
($crate::$enum_left::Struct($a), $crate::$enum_right::Struct($b)) => $body,
119+
_ => ::vortex_error::vortex_panic!("Mismatched vector types"),
120+
}
121+
}};
122+
}
123+
124+
/// Matches on pairs of vector variants and executes the same code for matching variant pairs.
125+
///
126+
/// This macro eliminates repetitive match statements when implementing operations that need to work
127+
/// with pairs of vectors where the variants must match.
128+
///
129+
/// Specify the types of the left and right vectors (either `Vector` or `VectorMut`) and the macro
130+
/// generates the appropriate match arms.
131+
///
132+
/// The macro binds the matched inner values to identifiers in the closure that can be used in the
133+
/// body expression.
134+
///
135+
/// # Examples
136+
///
137+
/// ```
138+
/// use vortex_vector::{
139+
/// BoolVector, BoolVectorMut, Vector, VectorMut, VectorMutOps, match_vector_pair
140+
/// };
141+
///
142+
/// fn extend_vector(left: &mut VectorMut, right: &Vector) {
143+
/// match_vector_pair!(left, right, |a: VectorMut, b: Vector| {
144+
/// a.extend_from_vector(b);
145+
/// })
146+
/// }
147+
///
148+
/// let mut mut_vec: VectorMut = BoolVectorMut::from_iter([true, false, true]).into();
149+
/// let vec: Vector = BoolVectorMut::from_iter([false, true]).freeze().into();
150+
///
151+
/// extend_vector(&mut mut_vec, &vec);
152+
/// assert_eq!(mut_vec.len(), 5);
153+
/// ```
154+
///
155+
/// Note that the vectors can also be owned:
156+
///
157+
/// ```
158+
/// use vortex_vector::{
159+
/// BoolVector, BoolVectorMut, Vector, VectorMut, VectorMutOps, match_vector_pair
160+
/// };
161+
///
162+
/// fn extend_vector_owned(mut dest: VectorMut, src: Vector) -> VectorMut {
163+
/// match_vector_pair!(&mut dest, src, |a: VectorMut, b: Vector| {
164+
/// a.extend_from_vector(&b);
165+
/// dest
166+
/// })
167+
/// }
168+
///
169+
/// let mut_vec: VectorMut = BoolVectorMut::from_iter([true, false, true]).into();
170+
/// let vec: Vector = BoolVectorMut::from_iter([false, true]).freeze().into();
171+
///
172+
/// let new_bool_mut = extend_vector_owned(mut_vec, vec);
173+
/// assert_eq!(new_bool_mut.len(), 5);
174+
/// ```
175+
#[macro_export] // DO NOT ADD `#[rustfmt::skip]`!!! https://github.com/rust-lang/rust/pull/52234#issuecomment-903419099
176+
macro_rules! match_vector_pair {
177+
($left:expr, $right:expr, | $a:ident : Vector, $b:ident : Vector | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, Vector, Vector, $a, $b, $body) }};
178+
($left:expr, $right:expr, | $a:ident : Vector, $b:ident : VectorMut | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, Vector, VectorMut, $a, $b, $body) }};
179+
($left:expr, $right:expr, | $a:ident : VectorMut, $b:ident : Vector | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, VectorMut, Vector, $a, $b, $body) }};
180+
($left:expr, $right:expr, | $a:ident : VectorMut, $b:ident : VectorMut | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, VectorMut, VectorMut, $a, $b, $body) }};
181+
}

vortex-vector/src/primitive/macros.rs

Lines changed: 22 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -44,56 +44,21 @@
4444
macro_rules! match_each_pvector {
4545
($self:expr, | $vec:ident | $body:block) => {{
4646
match $self {
47-
$crate::PrimitiveVector::U8(v) => {
48-
let $vec = v;
49-
$body
50-
}
51-
$crate::PrimitiveVector::U16(v) => {
52-
let $vec = v;
53-
$body
54-
}
55-
$crate::PrimitiveVector::U32(v) => {
56-
let $vec = v;
57-
$body
58-
}
59-
$crate::PrimitiveVector::U64(v) => {
60-
let $vec = v;
61-
$body
62-
}
63-
$crate::PrimitiveVector::I8(v) => {
64-
let $vec = v;
65-
$body
66-
}
67-
$crate::PrimitiveVector::I16(v) => {
68-
let $vec = v;
69-
$body
70-
}
71-
$crate::PrimitiveVector::I32(v) => {
72-
let $vec = v;
73-
$body
74-
}
75-
$crate::PrimitiveVector::I64(v) => {
76-
let $vec = v;
77-
$body
78-
}
79-
$crate::PrimitiveVector::F16(v) => {
80-
let $vec = v;
81-
$body
82-
}
83-
$crate::PrimitiveVector::F32(v) => {
84-
let $vec = v;
85-
$body
86-
}
87-
$crate::PrimitiveVector::F64(v) => {
88-
let $vec = v;
89-
$body
90-
}
47+
$crate::PrimitiveVector::U8($vec) => $body,
48+
$crate::PrimitiveVector::U16($vec) => $body,
49+
$crate::PrimitiveVector::U32($vec) => $body,
50+
$crate::PrimitiveVector::U64($vec) => $body,
51+
$crate::PrimitiveVector::I8($vec) => $body,
52+
$crate::PrimitiveVector::I16($vec) => $body,
53+
$crate::PrimitiveVector::I32($vec) => $body,
54+
$crate::PrimitiveVector::I64($vec) => $body,
55+
$crate::PrimitiveVector::F16($vec) => $body,
56+
$crate::PrimitiveVector::F32($vec) => $body,
57+
$crate::PrimitiveVector::F64($vec) => $body,
9158
}
9259
}};
9360
}
9461

95-
pub(crate) use match_each_pvector;
96-
9762
/// Matches on all primitive type variants of [`PrimitiveVectorMut`] and executes the same code
9863
/// for each variant branch.
9964
///
@@ -129,52 +94,17 @@ pub(crate) use match_each_pvector;
12994
macro_rules! match_each_pvector_mut {
13095
($self:expr, | $vec:ident | $body:block) => {{
13196
match $self {
132-
$crate::PrimitiveVectorMut::U8(v) => {
133-
let $vec = v;
134-
$body
135-
}
136-
$crate::PrimitiveVectorMut::U16(v) => {
137-
let $vec = v;
138-
$body
139-
}
140-
$crate::PrimitiveVectorMut::U32(v) => {
141-
let $vec = v;
142-
$body
143-
}
144-
$crate::PrimitiveVectorMut::U64(v) => {
145-
let $vec = v;
146-
$body
147-
}
148-
$crate::PrimitiveVectorMut::I8(v) => {
149-
let $vec = v;
150-
$body
151-
}
152-
$crate::PrimitiveVectorMut::I16(v) => {
153-
let $vec = v;
154-
$body
155-
}
156-
$crate::PrimitiveVectorMut::I32(v) => {
157-
let $vec = v;
158-
$body
159-
}
160-
$crate::PrimitiveVectorMut::I64(v) => {
161-
let $vec = v;
162-
$body
163-
}
164-
$crate::PrimitiveVectorMut::F16(v) => {
165-
let $vec = v;
166-
$body
167-
}
168-
$crate::PrimitiveVectorMut::F32(v) => {
169-
let $vec = v;
170-
$body
171-
}
172-
$crate::PrimitiveVectorMut::F64(v) => {
173-
let $vec = v;
174-
$body
175-
}
97+
$crate::PrimitiveVectorMut::U8($vec) => $body,
98+
$crate::PrimitiveVectorMut::U16($vec) => $body,
99+
$crate::PrimitiveVectorMut::U32($vec) => $body,
100+
$crate::PrimitiveVectorMut::U64($vec) => $body,
101+
$crate::PrimitiveVectorMut::I8($vec) => $body,
102+
$crate::PrimitiveVectorMut::I16($vec) => $body,
103+
$crate::PrimitiveVectorMut::I32($vec) => $body,
104+
$crate::PrimitiveVectorMut::I64($vec) => $body,
105+
$crate::PrimitiveVectorMut::F16($vec) => $body,
106+
$crate::PrimitiveVectorMut::F32($vec) => $body,
107+
$crate::PrimitiveVectorMut::F64($vec) => $body,
176108
}
177109
}};
178110
}
179-
180-
pub(crate) use match_each_pvector_mut;

vortex-vector/src/primitive/vector.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use vortex_dtype::half::f16;
77
use vortex_dtype::{NativePType, PType, PTypeDowncast, PTypeUpcast};
88
use vortex_error::vortex_panic;
99

10-
use super::macros::match_each_pvector;
11-
use crate::{PVector, PrimitiveVectorMut, VectorOps};
10+
use crate::{PVector, PrimitiveVectorMut, VectorOps, match_each_pvector};
1211

1312
/// An immutable vector of primitive values.
1413
///

vortex-vector/src/primitive/vector_mut.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use vortex_dtype::half::f16;
77
use vortex_dtype::{NativePType, PType, PTypeDowncast, PTypeUpcast};
88
use vortex_error::vortex_panic;
99

10-
use super::macros::match_each_pvector_mut;
11-
use crate::{PVectorMut, PrimitiveVector, VectorMutOps};
10+
use crate::{PVectorMut, PrimitiveVector, VectorMutOps, match_each_pvector_mut};
1211

1312
/// A mutable vector of primitive values.
1413
///

vortex-vector/src/struct_/vector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ pub struct StructVector {
3333

3434
/// The length of the vector (which is the same as all field vectors).
3535
///
36-
/// This is stored here as a convenience, and also helps in the case that the `StructVector` has
37-
/// no fields.
36+
/// This is stored here as a convenience, as the validity also tracks this information.
3837
pub(super) len: usize,
3938
}
4039

@@ -111,14 +110,14 @@ impl StructVector {
111110
}
112111
}
113112

114-
/// Decomposes the struct vector into its constituent parts (fields, validity, and length).
113+
/// Decomposes the struct vector into its constituent parts (fields and validity).
115114
pub fn into_parts(self) -> (Arc<Box<[Vector]>>, Mask) {
116115
(self.fields, self.validity)
117116
}
118117

119118
/// Returns the fields of the `StructVector`, each stored column-wise as a [`Vector`].
120-
pub fn fields(&self) -> &[Vector] {
121-
self.fields.as_ref()
119+
pub fn fields(&self) -> &Arc<Box<[Vector]>> {
120+
&self.fields
122121
}
123122
}
124123

@@ -138,6 +137,7 @@ impl VectorOps for StructVector {
138137
Self: Sized,
139138
{
140139
let len = self.len;
140+
141141
let fields = match Arc::try_unwrap(self.fields) {
142142
Ok(fields) => fields,
143143
Err(fields) => return Err(StructVector { fields, ..self }),

0 commit comments

Comments
 (0)