Returns the sum of values in the array. This doesn't detect overflow. Once overflowing, the result will wrap around. For an overflow-checking variant, use [`sum_array_checked`] instead.
(
array: A,
)
| 542 | /// This doesn't detect overflow. Once overflowing, the result will wrap around. |
| 543 | /// For an overflow-checking variant, use [`sum_array_checked`] instead. |
| 544 | pub fn sum_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>( |
| 545 | array: A, |
| 546 | ) -> Option<T::Native> { |
| 547 | match array.data_type() { |
| 548 | DataType::Dictionary(_, _) => { |
| 549 | let null_count = array.null_count(); |
| 550 | |
| 551 | if null_count == array.len() { |
| 552 | return None; |
| 553 | } |
| 554 | |
| 555 | let iter = ArrayIter::new(array); |
| 556 | let sum = iter |
| 557 | .into_iter() |
| 558 | .fold(T::default_value(), |accumulator, value| { |
| 559 | if let Some(value) = value { |
| 560 | accumulator.add_wrapping(value) |
| 561 | } else { |
| 562 | accumulator |
| 563 | } |
| 564 | }); |
| 565 | |
| 566 | Some(sum) |
| 567 | } |
| 568 | DataType::RunEndEncoded(run_ends, _) => match run_ends.data_type() { |
| 569 | DataType::Int16 => ree::sum_wrapping::<types::Int16Type, T>(&array), |
| 570 | DataType::Int32 => ree::sum_wrapping::<types::Int32Type, T>(&array), |
| 571 | DataType::Int64 => ree::sum_wrapping::<types::Int64Type, T>(&array), |
| 572 | _ => unreachable!(), |
| 573 | }, |
| 574 | _ => sum::<T>(as_primitive_array(&array)), |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /// Returns the sum of values in the array. |
| 579 | /// |
nothing calls this directly
no test coverage detected