doki23 commented on code in PR #3144:
URL: https://github.com/apache/arrow-rs/pull/3144#discussion_r1031395008
##########
arrow/src/compute/kernels/arity.rs:
##########
@@ -262,6 +328,79 @@ where
}
}
+/// Applies the provided fallible binary operation across `a` and `b` by
mutating the mutable
+/// [`PrimitiveArray`] `a` with the results, returning any error. If any index
is null in
+/// either `a` or `b`, the corresponding index in the result will also be null
+///
+/// Like [`try_unary`] the function is only evaluated for non-null indices
+///
+/// Mutable primitive array means that the buffer is not shared with other
arrays.
+/// As a result, this mutates the buffer directly without allocating new
buffer.
+///
+/// # Error
+///
+/// Return an error if the arrays have different lengths or
+/// the operation is under erroneous.
+/// This function gives error of original [`PrimitiveArray`] `a` if it is not
a mutable
+/// primitive array.
+pub fn try_binary_mut<T, F>(
+ a: PrimitiveArray<T>,
+ b: &PrimitiveArray<T>,
+ op: F,
+) -> std::result::Result<
+ PrimitiveArray<T>,
+ std::result::Result<PrimitiveArray<T>, ArrowError>,
+>
+where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native, T::Native) -> Result<T::Native>,
+{
+ if a.len() != b.len() {
+ return Err(Err(ArrowError::ComputeError(
+ "Cannot perform binary operation on arrays of different
length".to_string(),
+ )));
+ }
+ let len = a.len();
+
+ if a.is_empty() {
+ return Ok(PrimitiveArray::from(ArrayData::new_empty(&T::DATA_TYPE)));
+ }
Review Comment:
```suggestion
if a.is_empty() {
return Ok(PrimitiveArray::from(ArrayData::new_empty(&T::DATA_TYPE)));
}
let len = a.len();
```
--
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]