Compute SUM of a numeric column in a RecordBatch.
(batch: &RecordBatch, column_name: &str)
| 171 | |
| 172 | /// Compute SUM of a numeric column in a RecordBatch. |
| 173 | pub fn arrow_sum(batch: &RecordBatch, column_name: &str) -> Option<f64> { |
| 174 | let idx = batch.schema().index_of(column_name).ok()?; |
| 175 | let array = batch.column(idx); |
| 176 | |
| 177 | if let Some(f64_arr) = array.as_any().downcast_ref::<Float64Array>() { |
| 178 | Some(arrow::compute::kernels::aggregate::sum(f64_arr).unwrap_or(0.0)) |
| 179 | } else if let Some(i64_arr) = array.as_any().downcast_ref::<Int64Array>() { |
| 180 | let sum = arrow::compute::kernels::aggregate::sum(i64_arr).unwrap_or(0); |
| 181 | Some(sum as f64) |
| 182 | } else { |
| 183 | None |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /// Compute MIN of a numeric column using Arrow SIMD kernels. |
| 188 | pub fn arrow_min(batch: &RecordBatch, column_name: &str) -> Option<f64> { |