This function is called once per input row. `range`specifies which indexes of `values` should be considered for the calculation. Note this is the SLOWEST, but simplest, way to evaluate a window function. It is much faster to implement evaluate_all or evaluate_all_with_rank, if possible
(
&mut self,
values: &[ArrayRef],
range: &std::ops::Range<usize>,
)
| 205 | /// window function. It is much faster to implement |
| 206 | /// evaluate_all or evaluate_all_with_rank, if possible |
| 207 | fn evaluate( |
| 208 | &mut self, |
| 209 | values: &[ArrayRef], |
| 210 | range: &std::ops::Range<usize>, |
| 211 | ) -> Result<ScalarValue> { |
| 212 | // Again, the input argument is an array of floating |
| 213 | // point numbers to calculate a moving average |
| 214 | let arr: &Float64Array = values[0].as_ref().as_primitive::<Float64Type>(); |
| 215 | |
| 216 | let range_len = range.end - range.start; |
| 217 | |
| 218 | // our smoothing function will average all the values in the |
| 219 | let output = if range_len > 0 { |
| 220 | let sum: f64 = arr.values().iter().skip(range.start).take(range_len).sum(); |
| 221 | Some(sum / range_len as f64) |
| 222 | } else { |
| 223 | None |
| 224 | }; |
| 225 | |
| 226 | Ok(ScalarValue::Float64(output)) |
| 227 | } |
| 228 | } |