viirya commented on code in PR #2740:
URL: https://github.com/apache/arrow-rs/pull/2740#discussion_r973513909
##########
arrow/src/compute/kernels/arithmetic.rs:
##########
@@ -734,7 +802,84 @@ pub fn add_dyn(left: &dyn Array, right: &dyn Array) ->
Result<ArrayRef> {
_ => {
downcast_primitive_array!(
(left, right) => {
- math_op(left, right, |a, b| a + b).map(|a| Arc::new(a) as
ArrayRef)
+ math_op(left, right, |a, b| a.add_wrapping(b)).map(|a|
Arc::new(a) as ArrayRef)
+ }
+ _ => Err(ArrowError::CastError(format!(
+ "Unsupported data type {}, {}",
+ left.data_type(), right.data_type()
+ )))
+ )
+ }
+ }
+}
+
+/// Perform `left + right` operation on two arrays. If either left or right
value 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_dyn` instead.
+pub fn add_dyn_checked(left: &dyn Array, right: &dyn Array) ->
Result<ArrayRef> {
+ match left.data_type() {
+ DataType::Dictionary(_, _) => {
+ typed_dict_math_op!(
+ left,
+ right,
+ |a, b| a.add_checked(b),
+ math_checked_op_dict
+ )
+ }
+ DataType::Date32 => {
Review Comment:
Hmm, let me leave it as it is now. I'm wonder if we should do
checking/non-checking behavior on Data32/Date64.
--
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]