Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: BitPackedArray must be unsigned #930

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions encodings/fastlanes/src/bitpacking/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn bitpack_encode(array: PrimitiveArray, bit_width: usize) -> VortexResult<B

BitPackedArray::try_new(
packed,
array.ptype().to_unsigned(),
array.ptype(),
array.validity(),
patches,
bit_width,
Expand Down Expand Up @@ -348,7 +348,8 @@ mod test {
fn null_patches() {
let valid_values = (0..24).map(|v| v < 1 << 4).collect::<Vec<_>>();
let values =
PrimitiveArray::from_vec((0..24).collect::<Vec<_>>(), Validity::from(valid_values));
PrimitiveArray::from_vec((0u32..24).collect::<Vec<_>>(), Validity::from(valid_values));
assert!(values.ptype().is_unsigned_int());
let compressed = BitPackedArray::encode(values.as_ref(), 4).unwrap();
assert!(compressed.patches().is_none());
assert_eq!(
Expand Down Expand Up @@ -395,4 +396,14 @@ mod test {
assert_eq!(scalar, *v);
});
}

#[test]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should_panic? If you unwrap the error would be easier to assert

#[should_panic(expected = "expected type: uint but instead got i64")]
fn gh_issue_929() {
let values: Vec<i64> = (-500..500).collect();
let array = PrimitiveArray::from_vec(values, Validity::AllValid);
assert!(array.ptype().is_signed_int());

BitPackedArray::encode(array.as_ref(), 1024u32.ilog2() as usize).unwrap();
}
}
12 changes: 6 additions & 6 deletions encodings/fastlanes/src/bitpacking/compute/search_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ mod test {
#[test]
fn test_search_sorted_nulls() {
let bitpacked = BitPackedArray::encode(
PrimitiveArray::from_nullable_vec(vec![Some(1i64), None, None]).as_ref(),
PrimitiveArray::from_nullable_vec(vec![Some(1u64), None, None]).as_ref(),
2,
)
.unwrap();

let found = bitpacked
.search_sorted(
&Scalar::primitive(1i64, Nullability::Nullable),
&Scalar::primitive(1u64, Nullability::Nullable),
SearchSortedSide::Left,
)
.unwrap();
Expand All @@ -265,9 +265,9 @@ mod test {
// Test search_sorted_many with an array that contains several null values.
let bitpacked = BitPackedArray::encode(
PrimitiveArray::from_nullable_vec(vec![
Some(1i64),
Some(2i64),
Some(3i64),
Some(1u64),
Some(2u64),
Some(3u64),
None,
None,
None,
Expand All @@ -280,7 +280,7 @@ mod test {

let results = search_sorted_many(
bitpacked.as_ref(),
&[3i64, 2i64, 1i64],
&[3u64, 2u64, 1u64],
&[
SearchSortedSide::Left,
SearchSortedSide::Left,
Expand Down
Loading