pub fn sum<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
    T: ArrowNumericType,
    T::Native: Add<Output = T::Native>,
{
    let null_count = array.null_count();

    if null_count == array.len() {
        return None;
    }

    let mut n: T::Native = T::default_value();
    let data = array.data();
    let m = array.value_slice(0, data.len());

    if null_count == 0 {
        // optimized path for arrays without null values
        for item in m.iter().take(data.len()) {
            n = n + *item;
        }
    } else {
        for (i, item) in m.iter().enumerate() {
            if data.is_valid(i) {
                n = n + *item;
            }
        }
    }
    Some(n)
}
/// Returns the sum of values in the array.
///
/// Returns `None` if the array is empty or only contains null values.
Returns the sum of values in the array.
Returns `None` if the array is empty or only contains null values.
Returns the sum of values in the array . Returns ` None ` if the array is empty or only contains null values .
pub fn sum<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
    T: ArrowNumericType,
    T::Native: Add<Output = T::Native>,
{
    let null_count = array.null_count();
    if null_count == array.len() {
        return None;
    }
    let mut n: T::Native = T::default_value();
    let data = array.data();
    let m = array.value_slice(0, data.len());
    if null_count == 0 {
        // optimized path for arrays without null values
        for item in m.iter().take(data.len()) {
            n = n + *item;
        }
    } else {
        for (i, item) in m.iter().enumerate() {
            if data.is_valid(i) {
                n = n + *item;
            }
        }
    }
    Some(n)
}
pub fn sum < T > ( array : & PrimitiveArray < T > ) -> Option < T :: Native > where T : ArrowNumericType , T :: Native : Add < Output = T :: Native > , { let null_count = array . null_count ( ) ; if null_count == array . len ( ) { return None ; } let mut n : T :: Native = T :: default_value ( ) ; let data = array . data ( ) ; let m = array . value_slice ( 0 , data . len ( ) ) ; if null_count == 0 { // optimized path for arrays without null values for item in m . iter ( ) . take ( data . len ( ) ) { n = n + * item ; } } else { for ( i , item ) in m . iter ( ) . enumerate ( ) { if data . is_valid ( i ) { n = n + * item ; } } } Some ( n ) }
Returns the sum of values in the array.
Returns the sum of values in the array .
array
&PrimitiveArray<T>