Aggregate `field` over the slice `indices[start_idx..=end_idx]`.
(
all_vals: &[Option<f64>],
indices: &[usize],
rows: &[(String, serde_json::Value)],
field: &str,
spec: &WindowFuncSpec,
start_idx: usize,
end_idx: usize,
)
| 108 | |
| 109 | /// Aggregate `field` over the slice `indices[start_idx..=end_idx]`. |
| 110 | fn aggregate_slice( |
| 111 | all_vals: &[Option<f64>], |
| 112 | indices: &[usize], |
| 113 | rows: &[(String, serde_json::Value)], |
| 114 | field: &str, |
| 115 | spec: &WindowFuncSpec, |
| 116 | start_idx: usize, |
| 117 | end_idx: usize, |
| 118 | ) -> serde_json::Value { |
| 119 | let slice_vals: Vec<f64> = all_vals[start_idx..=end_idx] |
| 120 | .iter() |
| 121 | .filter_map(|v| *v) |
| 122 | .collect(); |
| 123 | let slice_count = end_idx - start_idx + 1; |
| 124 | |
| 125 | match spec.func_name.as_str() { |
| 126 | "sum" => { |
| 127 | let rt = crate::simd_agg::ts_runtime(); |
| 128 | serde_json::json!((rt.sum_f64)(&slice_vals)) |
| 129 | } |
| 130 | "count" => serde_json::json!(slice_count), |
| 131 | "avg" => { |
| 132 | if slice_vals.is_empty() { |
| 133 | serde_json::Value::Null |
| 134 | } else { |
| 135 | let rt = crate::simd_agg::ts_runtime(); |
| 136 | serde_json::json!((rt.sum_f64)(&slice_vals) / slice_vals.len() as f64) |
| 137 | } |
| 138 | } |
| 139 | "min" => { |
| 140 | if slice_vals.is_empty() { |
| 141 | serde_json::Value::Null |
| 142 | } else { |
| 143 | let rt = crate::simd_agg::ts_runtime(); |
| 144 | serde_json::json!((rt.min_f64)(&slice_vals)) |
| 145 | } |
| 146 | } |
| 147 | "max" => { |
| 148 | if slice_vals.is_empty() { |
| 149 | serde_json::Value::Null |
| 150 | } else { |
| 151 | let rt = crate::simd_agg::ts_runtime(); |
| 152 | serde_json::json!((rt.max_f64)(&slice_vals)) |
| 153 | } |
| 154 | } |
| 155 | "first_value" => indices |
| 156 | .get(start_idx) |
| 157 | .map(|&i| get_field(&rows[i].1, field)) |
| 158 | .unwrap_or(serde_json::Value::Null), |
| 159 | "last_value" => indices |
| 160 | .get(end_idx) |
| 161 | .map(|&i| get_field(&rows[i].1, field)) |
| 162 | .unwrap_or(serde_json::Value::Null), |
| 163 | _ => serde_json::Value::Null, |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | #[cfg(test)] |
no test coverage detected