alamb commented on code in PR #6098:
URL: https://github.com/apache/arrow-datafusion/pull/6098#discussion_r1175385654
##########
datafusion/physical-expr/src/expressions/binary/kernels.rs:
##########
@@ -56,41 +60,64 @@ macro_rules! binary_bitwise_array_scalar {
}};
}
-pub(crate) fn bitwise_and(left: ArrayRef, right: ArrayRef) -> Result<ArrayRef>
{
- match &left.data_type() {
- DataType::Int8 => {
- binary_bitwise_array_op!(left, right, |a: i8, b: i8| a & b,
Int8Array)
- }
- DataType::Int16 => {
- binary_bitwise_array_op!(left, right, |a: i16, b: i16| a & b,
Int16Array)
- }
- DataType::Int32 => {
- binary_bitwise_array_op!(left, right, |a: i32, b: i32| a & b,
Int32Array)
- }
- DataType::Int64 => {
- binary_bitwise_array_op!(left, right, |a: i64, b: i64| a & b,
Int64Array)
- }
- DataType::UInt8 => {
- binary_bitwise_array_op!(left, right, |a: u8, b: u8| a & b,
UInt8Array)
- }
- DataType::UInt16 => {
- binary_bitwise_array_op!(left, right, |a: u16, b: u16| a & b,
UInt16Array)
- }
- DataType::UInt32 => {
- binary_bitwise_array_op!(left, right, |a: u32, b: u32| a & b,
UInt32Array)
- }
- DataType::UInt64 => {
- binary_bitwise_array_op!(left, right, |a: u64, b: u64| a & b,
UInt64Array)
+/// Downcasts $LEFT and $RIGHT to $ARRAY_TYPE and then calls $KERNEL($LEFT,
$RIGHT)
+macro_rules! call_bitwise_kernel {
+ ($LEFT:expr, $RIGHT:expr, $KERNEL:expr, $ARRAY_TYPE:ident) => {{
+ let left = $LEFT.as_any().downcast_ref::<$ARRAY_TYPE>().unwrap();
+ let right = $RIGHT.as_any().downcast_ref::<$ARRAY_TYPE>().unwrap();
+ let result: $ARRAY_TYPE = $KERNEL(left, right)?;
+ Ok(Arc::new(result))
+ }};
+}
+
+/// Creates a $FUNC(left: ArrayRef, right: ArrayRef) that
+/// downcasts left / right to the appropriate integral type and calls the
kernel
+macro_rules! create_dyn_kernel {
+ ($FUNC:ident, $KERNEL:ident) => {
+ pub(crate) fn $FUNC(left: ArrayRef, right: ArrayRef) ->
Result<ArrayRef> {
+ match &left.data_type() {
+ DataType::Int8 => {
+ call_bitwise_kernel!(left, right, $KERNEL, Int8Array)
+ }
+ DataType::Int16 => {
+ call_bitwise_kernel!(left, right, $KERNEL, Int16Array)
+ }
+ DataType::Int32 => {
+ call_bitwise_kernel!(left, right, $KERNEL, Int32Array)
+ }
+ DataType::Int64 => {
+ call_bitwise_kernel!(left, right, $KERNEL, Int64Array)
+ }
+ DataType::UInt8 => {
+ call_bitwise_kernel!(left, right, $KERNEL, UInt8Array)
+ }
+ DataType::UInt16 => {
+ call_bitwise_kernel!(left, right, $KERNEL, UInt16Array)
+ }
+ DataType::UInt32 => {
+ call_bitwise_kernel!(left, right, $KERNEL, UInt32Array)
+ }
+ DataType::UInt64 => {
+ call_bitwise_kernel!(left, right, $KERNEL, UInt64Array)
+ }
+ other => Err(DataFusionError::Internal(format!(
+ "Data type {:?} not supported for binary operation '{}' on
dyn arrays",
+ other,
+ stringify!($KERNEL),
+ ))),
+ }
}
- other => Err(DataFusionError::Internal(format!(
- "Data type {:?} not supported for binary operation '{}' on dyn
arrays",
- other,
- Operator::BitwiseAnd
- ))),
- }
+ };
}
-pub(crate) fn bitwise_shift_right(left: ArrayRef, right: ArrayRef) ->
Result<ArrayRef> {
+create_dyn_kernel!(bitwise_or_dyn, bitwise_or);
+create_dyn_kernel!(bitwise_xor_dyn, bitwise_xor);
+create_dyn_kernel!(bitwise_and_dyn, bitwise_and);
+
+pub(crate) fn bitwise_shift_right_dyn(
Review Comment:
I also found the upstream tracking ticket in arrow --
https://github.com/apache/arrow-rs/issues/2741 and added links in the code here
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]