Skip to content

Commit a4cf669

Browse files
authored
fix: decimal precision/scale for fuzz (#3266)
Signed-off-by: Andrew Duffy <[email protected]>
1 parent 6319414 commit a4cf669

File tree

5 files changed

+759
-9
lines changed

5 files changed

+759
-9
lines changed

vortex-dtype/src/arbitrary.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::sync::Arc;
22

33
use arbitrary::{Arbitrary, Result, Unstructured};
44

5-
use crate::{DType, DecimalDType, FieldName, FieldNames, Nullability, PType, StructDType};
5+
use crate::{
6+
DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE, DType, DecimalDType, FieldName, FieldNames,
7+
Nullability, PType, StructDType,
8+
};
69

710
impl<'a> Arbitrary<'a> for DType {
811
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
@@ -65,11 +68,15 @@ impl<'a> Arbitrary<'a> for PType {
6568
}
6669

6770
impl<'a> Arbitrary<'a> for DecimalDType {
68-
#[allow(clippy::unwrap_in_result, clippy::expect_used)]
71+
#[allow(
72+
clippy::unwrap_in_result,
73+
clippy::expect_used,
74+
clippy::cast_possible_truncation
75+
)]
6976
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
7077
// Get a random integer for the scale
71-
let precision = u8::try_from(u.int_in_range(0..=38)?).expect("u8 overflow");
72-
let scale = i8::try_from(u.int_in_range(-38..=38)?).expect("i8 overflow");
78+
let precision = u.int_in_range(1..=DECIMAL256_MAX_PRECISION)?;
79+
let scale = u.int_in_range(-DECIMAL256_MAX_SCALE..=(precision as i8))?;
7380
Ok(Self::new(precision, scale))
7481
}
7582
}

vortex-dtype/src/decimal.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ const MAX_SCALE: i8 = 76;
88
/// Maximum precision for a Decimal128 type from Arrow
99
pub const DECIMAL128_MAX_PRECISION: u8 = 38;
1010

11+
/// Maximum precision for a Decimal256 type from Arrow
12+
pub const DECIMAL256_MAX_PRECISION: u8 = 76;
13+
14+
/// Maximum sacle for a Decimal128 type from Arrow
15+
pub const DECIMAL128_MAX_SCALE: i8 = 38;
16+
17+
/// Maximum sacle for a Decimal256 type from Arrow
18+
pub const DECIMAL256_MAX_SCALE: i8 = 76;
19+
1120
/// Parameters that define the precision and scale of a decimal type.
1221
///
1322
/// Decimal types allow real numbers with a similar precision and scale to be represented exactly.

0 commit comments

Comments
 (0)