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: Signed bitpacked arrays handle searching for negative values #1800

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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
19 changes: 16 additions & 3 deletions encodings/fastlanes/src/bitpacking/compute/search_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ where
// in the BitPackedSearch. We need a type that impls fastlanes::BitPack, and it is a
// precondition for BitPackedArray that all values must be non-negative, so promotion
// is cheap and safe.
let native_value: T = value
.cast(&DType::from(array.ptype().to_unsigned()))?
.try_into()?;
let Ok(unsigned_value) = value.cast(&DType::from(array.ptype().to_unsigned())) else {
// If the value can't be casted to unsigned dtype then it can't exist in the array and would be smaller than any value present
return Ok(SearchResult::NotFound(0));
};
let native_value: T = unsigned_value.try_into()?;
search_sorted_native(array, native_value, side)
}

Expand Down Expand Up @@ -330,4 +332,15 @@ mod test {
]
);
}

#[test]
fn test_missing_signed() {
let bitpacked = BitPackedArray::encode(&buffer![1i32, 2, 3, 4, 5].into_array(), 2)
.unwrap()
.into_array();
assert_eq!(
search_sorted(&bitpacked, -4, SearchSortedSide::Left).unwrap(),
SearchResult::NotFound(0)
);
}
}
Loading