sunchao commented on code in PR #2713:
URL: https://github.com/apache/arrow-rs/pull/2713#discussion_r969859994
##########
arrow/src/compute/kernels/arithmetic.rs:
##########
@@ -834,12 +834,34 @@ where
/// Add every value in an array by a scalar. If any value in the array is null
then the
/// result is also null. The given array must be a `PrimitiveArray` of the
type same as
/// the scalar, or a `DictionaryArray` of the value type same as the scalar.
+///
+/// This doesn't detect overflow. Once overflowing, the result will wrap
around.
+/// For an overflow-checking variant, use `add_scalar_checked_dyn` instead.
pub fn add_scalar_dyn<T>(array: &dyn Array, scalar: T::Native) ->
Result<ArrayRef>
where
T: ArrowNumericType,
- T::Native: Add<Output = T::Native>,
+ T::Native: ArrowNativeTypeOp,
{
- unary_dyn::<_, T>(array, |value| value + scalar)
+ unary_dyn::<_, T>(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. The given array must be a `PrimitiveArray` of the
type same as
+/// the scalar, or a `DictionaryArray` of the value type same as the scalar.
+///
+/// This detects overflow and returns an `Err` for that. For an
non-overflow-checking variant,
+/// use `add_scalar_dyn` instead.
+pub fn add_scalar_checked_dyn<T>(array: &dyn Array, scalar: T::Native) ->
Result<ArrayRef>
Review Comment:
I see. I wonder if we should point that out in the doc of this method, in
case it's not obvious to the users.
--
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]