Skip to content
Closed
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
30 changes: 24 additions & 6 deletions rust/arrow/src/compute/kernels/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ macro_rules! compare_op {
let null_bit_buffer =
combine_option_bitmap($left.data_ref(), $right.data_ref(), $left.len())?;

let mut result = BooleanBufferBuilder::new($left.len());
let byte_capacity = bit_util::ceil($left.len(), 8);
let actual_capacity = bit_util::round_upto_multiple_of_64(byte_capacity);
let mut buffer = MutableBuffer::new(actual_capacity);
buffer.resize(byte_capacity);

let data = buffer.raw_data_mut();
for i in 0..$left.len() {
result.append($op($left.value(i), $right.value(i)))?;
if $op($left.value(i), $right.value(i)) {
unsafe {
bit_util::set_bit_raw(data, i);
}
}
}

let data = ArrayData::new(
Expand All @@ -58,7 +67,7 @@ macro_rules! compare_op {
None,
null_bit_buffer,
0,
vec![result.finish()],
vec![buffer.freeze()],
vec![],
);
Ok(PrimitiveArray::<BooleanType>::from(Arc::new(data)))
Expand All @@ -68,9 +77,18 @@ macro_rules! compare_op {
macro_rules! compare_op_scalar {
($left: expr, $right:expr, $op:expr) => {{
let null_bit_buffer = $left.data().null_buffer().cloned();
let mut result = BooleanBufferBuilder::new($left.len());
let byte_capacity = bit_util::ceil($left.len(), 8);
let actual_capacity = bit_util::round_upto_multiple_of_64(byte_capacity);
let mut buffer = MutableBuffer::new(actual_capacity);
buffer.resize(byte_capacity);

let data = buffer.raw_data_mut();
for i in 0..$left.len() {
result.append($op($left.value(i), $right))?;
if $op($left.value(i), $right) {
unsafe {
bit_util::set_bit_raw(data, i);
}
}
Comment on lines -71 to +91
Copy link
Member

Choose a reason for hiding this comment

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

A side note: In general, if we are bypassing builders for speed, it can mean that builders are not a good abstraction, as they significantly impact performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, would be nice to see if we can get the combination of a clean/safe API and good performance as well.

}

let data = ArrayData::new(
Expand All @@ -79,7 +97,7 @@ macro_rules! compare_op_scalar {
None,
null_bit_buffer,
0,
vec![result.finish()],
vec![buffer.freeze()],
vec![],
);
Ok(PrimitiveArray::<BooleanType>::from(Arc::new(data)))
Expand Down