Skip to content

Commit

Permalink
fix: Signed bitpacked arrays handle searching for negative values (#1800
Browse files Browse the repository at this point in the history
)
  • Loading branch information
robert3005 authored Jan 3, 2025
1 parent 5a704cf commit 29da540
Showing 1 changed file with 16 additions and 3 deletions.
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)
);
}
}

0 comments on commit 29da540

Please sign in to comment.