Skip to content

Commit

Permalink
Use bit_slice in combine_option_bitmap (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann authored Jun 18, 2022
1 parent 2c7df9f commit c7f89e1
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions arrow/src/compute/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub(super) fn combine_option_bitmap(
Err(ArrowError::ComputeError(
"Arrays must not be empty".to_string(),
)),
|(buffer, offset)| Ok(buffer.map(|buffer| buffer.slice(offset))),
|(buffer, offset)| {
Ok(buffer.map(|buffer| buffer.bit_slice(offset, len_in_bits)))
},
)
}

Expand Down Expand Up @@ -185,7 +187,7 @@ pub(super) mod tests {
offset: usize,
null_bit_buffer: Option<Buffer>,
) -> Arc<ArrayData> {
let buffer = Buffer::from(&vec![11; len]);
let buffer = Buffer::from(&vec![11; len + offset]);

Arc::new(
ArrayData::try_new(
Expand Down Expand Up @@ -256,6 +258,41 @@ pub(super) mod tests {
);
}

#[test]
fn test_combine_option_bitmap_with_offsets() {
let none_bitmap = make_data_with_null_bit_buffer(8, 0, None);
let bitmap0 =
make_data_with_null_bit_buffer(8, 0, Some(Buffer::from([0b10101010])));
let bitmap1 =
make_data_with_null_bit_buffer(8, 1, Some(Buffer::from([0b01010100, 0b1])));
let bitmap2 =
make_data_with_null_bit_buffer(8, 2, Some(Buffer::from([0b10101000, 0b10])));
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&bitmap1], 8).unwrap()
);
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&bitmap2], 8).unwrap()
);
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&bitmap1, &none_bitmap], 8).unwrap()
);
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&none_bitmap, &bitmap2], 8).unwrap()
);
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&bitmap0, &bitmap1], 8).unwrap()
);
assert_eq!(
Some(Buffer::from([0b10101010])),
combine_option_bitmap(&[&bitmap1, &bitmap2], 8).unwrap()
);
}

#[test]
fn test_compare_option_bitmap() {
let none_bitmap = make_data_with_null_bit_buffer(8, 0, None);
Expand Down

0 comments on commit c7f89e1

Please sign in to comment.