Dandandan commented on a change in pull request #844: URL: https://github.com/apache/arrow-rs/pull/844#discussion_r734473747
########## File path: arrow/src/compute/kernels/comparison.rs ########## @@ -623,6 +624,107 @@ pub fn eq_utf8_scalar<OffsetSize: StringOffsetSizeTrait>( compare_op_scalar!(left, right, |a, b| a == b) } +/// Perform `left == right` operation on [`BooleanArray`] +fn eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { + binary_boolean_kernel( + left, + right, + |left: &Buffer, + left_offset_in_bits: usize, + right: &Buffer, + right_offset_in_bits: usize, + len_in_bits: usize| { + bitwise_bin_op_helper( + left, + left_offset_in_bits, + right, + right_offset_in_bits, + len_in_bits, + |a, b| !(a ^ b), + ) + }, + ) +} + +/// Perform `left != right` operation on [`BooleanArray`] +fn neq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { + binary_boolean_kernel( + left, + right, + |left: &Buffer, + left_offset_in_bits: usize, + right: &Buffer, + right_offset_in_bits: usize, + len_in_bits: usize| { + bitwise_bin_op_helper( + left, + left_offset_in_bits, + right, + right_offset_in_bits, + len_in_bits, + |a, b| (a ^ b), + ) + }, + ) +} + +/// Perform `left == right` operation on [`BooleanArray`] and a scalar +fn eq_bool_scalar(left: &BooleanArray, right: bool) -> Result<BooleanArray> { + let len = left.len(); + let left_offset = left.offset(); + + let values = if right { + left.values().bit_slice(left_offset, len) + } else { + buffer_unary_not(left.values(), left.offset(), left.len()) + }; + + let data = unsafe { + ArrayData::new_unchecked( + DataType::Boolean, + len, + None, + left.data_ref() + .null_bitmap() + .as_ref() + .map(|b| b.bits.bit_slice(left_offset, len)), + 0, + vec![values], + vec![], + ) + }; + + Ok(BooleanArray::from(data)) +} + +/// Perform `left != right` operation on [`BooleanArray`] and a scalar +fn neq_bool_scalar(left: &BooleanArray, right: bool) -> Result<BooleanArray> { + let len = left.len(); Review comment: Good idea! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org