Skip to content

Commit 19a2d89

Browse files
committed
fix[array]: invalid arbitrary decimal scalar value
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 13464da commit 19a2d89

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

vortex-array/src/builders/decimal.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ impl Default for DecimalBuffer {
284284
#[cfg(test)]
285285
mod tests {
286286
use vortex_dtype::DecimalDType;
287-
288-
289287

290288
use crate::arrays::DecimalArray;
291289
use crate::assert_arrays_eq;

vortex-dtype/src/decimal/precision.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,18 @@ impl<D: NativeDecimalType> TryFrom<&DecimalDType> for PrecisionScale<D> {
122122
PrecisionScale::try_new(value.precision, value.scale)
123123
}
124124
}
125+
126+
#[cfg(test)]
127+
mod tests {
128+
use crate::PrecisionScale;
129+
130+
#[test]
131+
fn max_precision() {
132+
let prec = PrecisionScale::<i8>::new(2, 1);
133+
assert!(prec.is_valid(8));
134+
assert!(prec.is_valid(99));
135+
assert!(prec.is_valid(-9));
136+
assert!(prec.is_valid(0));
137+
assert!(prec.is_valid(-99))
138+
}
139+
}

vortex-dtype/src/decimal/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ macro_rules! impl_decimal {
127127
const MAX_SCALE: i8 = Self::MAX_PRECISION as i8;
128128

129129
const MIN_BY_PRECISION: &'static [Self] = &{
130-
let mut mins = [$T::ZERO; Self::MAX_PRECISION as usize];
130+
let mut mins = [$T::ZERO; Self::MAX_PRECISION as usize + 1];
131131
let mut p = $T::ONE;
132132
let mut i = 0;
133133
while i < Self::MAX_PRECISION as usize {
134134
p = p * 10;
135-
mins[i] = -(p - 1);
135+
mins[i + 1] = -(p - 1);
136136
i += 1;
137137
}
138138
mins
139139
};
140140

141141
const MAX_BY_PRECISION: &'static [Self] = &{
142-
let mut maxs = [$T::ZERO; Self::MAX_PRECISION as usize];
142+
let mut maxs = [$T::ZERO; Self::MAX_PRECISION as usize + 1];
143143
let mut p = $T::ONE;
144144
let mut i = 0;
145145
while i < Self::MAX_PRECISION as usize {
146146
p = p * 10;
147-
maxs[i] = p - 1;
147+
maxs[i + 1] = p - 1;
148148
i += 1;
149149
}
150150
maxs

vortex-scalar/src/arbitrary.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ pub fn random_decimal(u: &mut Unstructured, decimal_type: &DecimalDType) -> Resu
8686
let precision = decimal_type.precision();
8787
let value = match_each_decimal_value_type!(smallest_decimal_value_type(decimal_type), |D| {
8888
DecimalValue::from(u.int_in_range(
89-
D::MIN_BY_PRECISION[precision as usize - 1]
90-
..=D::MAX_BY_PRECISION[precision as usize - 1],
89+
D::MIN_BY_PRECISION[precision as usize]..=D::MAX_BY_PRECISION[precision as usize],
9190
)?)
9291
});
9392

0 commit comments

Comments
 (0)