liukun4515 commented on a change in pull request #1408:
URL: https://github.com/apache/arrow-datafusion/pull/1408#discussion_r769197681
##########
File path: datafusion/src/physical_plan/expressions/sum.rs
##########
@@ -153,9 +163,34 @@ macro_rules! typed_sum_delta_batch {
}};
}
+// TODO implement this in arrow-rs with simd
+// https://github.com/apache/arrow-rs/issues/1010
+fn sum_decimal_batch(
+ values: &ArrayRef,
+ precision: &usize,
+ scale: &usize,
+) -> Result<ScalarValue> {
+ let array = values.as_any().downcast_ref::<DecimalArray>().unwrap();
+
+ if array.null_count() == array.len() {
+ return Ok(ScalarValue::Decimal128(None, *precision, *scale));
+ }
+
+ let mut result = 0_i128;
+ for i in 0..array.len() {
+ if array.is_valid(i) {
+ result += array.value(i);
Review comment:
I just can check the overflow in the `eval` function.
When the result reaches the MAX of range (decimal(p,s)), but other values
will affect the result.
If the MAX is `100` and now the result is 200 and the remaining values is
[-100,-50], we can't throw overflow error or check overflow in the middle of
calculation.
--
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]