liukun4515 commented on code in PR #2650:
URL: https://github.com/apache/arrow-rs/pull/2650#discussion_r963231823
##########
arrow/src/compute/kernels/arithmetic.rs:
##########
@@ -895,15 +895,34 @@ pub fn add_dyn(left: &dyn Array, right: &dyn Array) ->
Result<ArrayRef> {
/// Add every value in an array by a scalar. If any value in the array is null
then the
/// result is also null.
+///
+/// This doesn't detect overflow. Once overflowing, the result will wrap
around.
+/// For an overflow-checking variant, use `add_scalar_checked` instead.
pub fn add_scalar<T>(
array: &PrimitiveArray<T>,
scalar: T::Native,
) -> Result<PrimitiveArray<T>>
where
T: datatypes::ArrowNumericType,
- T::Native: Add<Output = T::Native>,
+ T::Native: ArrowNativeTypeOp,
+{
+ Ok(unary(array, |value| value.add_wrapping(scalar)))
+}
+
+/// Add every value in an array by a scalar. If any value in the array is null
then the
+/// result is also null.
+///
+/// This detects overflow and returns an `Err` for that. For an
non-overflow-checking variant,
+/// use `add_scalar` instead.
+pub fn add_scalar_checked<T>(
+ array: &PrimitiveArray<T>,
+ scalar: T::Native,
+) -> Result<PrimitiveArray<T>>
+where
+ T: datatypes::ArrowNumericType,
+ T::Native: ArrowNativeTypeOp,
{
- Ok(unary(array, |value| value + scalar))
+ unary_checked(array, |value| value.add_checked(scalar))
Review Comment:
after this https://github.com/apache/arrow-rs/pull/2650/files#r963221429
you can define characteristic error message for this closures
--
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]