Skip to content

Commit

Permalink
Forbid for encoding with wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 committed Jun 24, 2024
1 parent 1fb03ae commit 139687c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions encodings/fastlanes/src/for/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl EncodingCompression for FoREncoding {
return None;
}

match_each_integer_ptype!(parray.ptype(), |$P| {
let min: $P = parray.statistics().compute_min()?;
let max: $P = parray.statistics().compute_max()?;
let _subbed = max.wrapping_sub(min);
if max.wrapping_sub(min) < max {
return None;
}
});

Some(self)
}

Expand Down Expand Up @@ -200,9 +209,11 @@ mod test {

#[test]
fn test_overflow() {
// Create a range offset by a million
let array = PrimitiveArray::from((i8::MIN..i8::MAX).collect_vec());
let compressed = FoREncoding {}
let array = PrimitiveArray::from((i8::MIN..=i8::MAX).collect_vec());
assert!(FoREncoding
.can_compress(array.array(), &CompressConfig::default())
.is_none());
let compressed = FoREncoding
.compress(array.array(), None, Compressor::new(&ctx()))
.unwrap();
let compressed = FoRArray::try_from(compressed).unwrap();
Expand Down

0 comments on commit 139687c

Please sign in to comment.