Skip to content

Commit eb3558f

Browse files
committed
clean up decimal vector modules and docs
Signed-off-by: Connor Tsui <[email protected]>
1 parent f6c19be commit eb3558f

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

vortex-vector/src/decimal/generic.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,26 @@ pub struct DVector<D> {
1717
}
1818

1919
impl<D: NativeDecimalType> DVector<D> {
20+
/// Try to create a new decimal vector from the given elements and validity.
21+
///
22+
/// # Panics
23+
///
24+
/// Panics if:
25+
///
26+
/// - The lengths of the `elements` and `validity` do not match.
27+
/// - Any of the elements are out of bounds for the given [`PrecisionScale`].
28+
pub fn new(ps: PrecisionScale<D>, elements: Buffer<D>, validity: Mask) -> Self {
29+
Self::try_new(ps, elements, validity).vortex_expect("Failed to create `DVector`")
30+
}
31+
2032
/// Try to create a new decimal vector from the given elements and validity.
2133
///
2234
/// # Errors
2335
///
24-
/// Returns an error if the precision/scale is invalid, the lengths of the elements
25-
/// and validity do not match, or any of the elements are out of bounds for the given
26-
/// precision/scale.
36+
/// Returns an error if:
37+
///
38+
/// - The lengths of the `elements` and `validity` do not match.
39+
/// - Any of the elements are out of bounds for the given [`PrecisionScale`].
2740
pub fn try_new(
2841
ps: PrecisionScale<D>,
2942
elements: Buffer<D>,
@@ -57,8 +70,10 @@ impl<D: NativeDecimalType> DVector<D> {
5770
///
5871
/// # Safety
5972
///
60-
/// The caller must ensure that the precision/scale is valid, the lengths of the elements
61-
/// and validity match, and all the elements are within bounds for the given precision/scale.
73+
/// The caller must ensure:
74+
///
75+
/// - The lengths of the elements and validity are equal.
76+
/// - All elements are in bounds for the given [`PrecisionScale`].
6277
pub unsafe fn new_unchecked(
6378
ps: PrecisionScale<D>,
6479
elements: Buffer<D>,
@@ -75,15 +90,16 @@ impl<D: NativeDecimalType> DVector<D> {
7590
}
7691
}
7792

93+
/// Decomposes the decimal vector into its constituent parts ([`PrecisionScale`], decimal
94+
/// buffer, and validity).
95+
pub fn into_parts(self) -> (PrecisionScale<D>, Buffer<D>, Mask) {
96+
(self.ps, self.elements, self.validity)
97+
}
98+
7899
/// Get the precision/scale of the decimal vector.
79100
pub fn precision_scale(&self) -> PrecisionScale<D> {
80101
self.ps
81102
}
82-
83-
/// Decomposes the decimal vector into its constituent parts (precision/scale, buffer and validity).
84-
pub fn into_parts(self) -> (PrecisionScale<D>, Buffer<D>, Mask) {
85-
(self.ps, self.elements, self.validity)
86-
}
87103
}
88104

89105
impl<D: NativeDecimalType> VectorOps for DVector<D> {

vortex-vector/src/decimal/generic_mut_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ impl<D: NativeDecimalType> DVectorMut<D> {
2626
if !self.ps.is_valid(value) {
2727
vortex_bail!("Value {:?} is out of bounds for {}", value, self.ps,);
2828
}
29+
2930
self.elements.push(value);
3031
self.validity.append_n(true, 1);
3132
Ok(())
3233
}
3334

3435
/// Returns a mutable reference to the underlying elements buffer.
3536
///
36-
/// # SAFETY
37+
/// # Safety
3738
///
3839
/// Modifying the elements buffer directly may violate the precision/scale constraints.
3940
/// The caller must ensure that any modifications maintain these invariants.

vortex-vector/src/decimal/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
mod generic;
5+
pub use generic::DVector;
6+
57
mod generic_mut;
68
mod generic_mut_impl;
7-
mod macros;
9+
pub use generic_mut::DVectorMut;
10+
811
mod vector;
12+
pub use vector::DecimalVector;
13+
914
mod vector_mut;
15+
pub use vector_mut::DecimalVectorMut;
16+
17+
mod macros;
1018

11-
pub use generic::*;
12-
pub use generic_mut::*;
13-
pub use vector::*;
14-
pub use vector_mut::*;
1519
use vortex_dtype::NativeDecimalType;
1620

1721
use crate::{Vector, VectorMut};
@@ -22,18 +26,18 @@ impl From<DecimalVector> for Vector {
2226
}
2327
}
2428

25-
impl<D: NativeDecimalType> From<DVector<D>> for Vector {
26-
fn from(v: DVector<D>) -> Self {
27-
Self::Decimal(DecimalVector::from(v))
28-
}
29-
}
30-
3129
impl<D: NativeDecimalType> From<DVector<D>> for DecimalVector {
3230
fn from(value: DVector<D>) -> Self {
3331
D::upcast(value)
3432
}
3533
}
3634

35+
impl<D: NativeDecimalType> From<DVector<D>> for Vector {
36+
fn from(v: DVector<D>) -> Self {
37+
Self::Decimal(DecimalVector::from(v))
38+
}
39+
}
40+
3741
impl From<DecimalVectorMut> for VectorMut {
3842
fn from(v: DecimalVectorMut) -> Self {
3943
Self::Decimal(v)

vortex-vector/src/primitive/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ mod generic;
1818
pub use generic::PVector;
1919

2020
mod generic_mut;
21+
mod generic_mut_impl;
22+
mod iter;
2123
pub use generic_mut::PVectorMut;
2224

2325
mod vector;
2426
pub use vector::PrimitiveVector;
2527

26-
mod generic_mut_impl;
27-
mod iter;
2828
mod vector_mut;
2929
pub use vector_mut::PrimitiveVectorMut;
3030

0 commit comments

Comments
 (0)