MCPcopy Create free account
hub / github.com/apache/datafusion / evaluate

Method evaluate

datafusion-examples/examples/udf/simple_udwf.rs:207–227  ·  view source on GitHub ↗

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>,
    )

Source from the content-addressed store, hash-verified

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}

Callers 2

evaluate_demoFunction · 0.45
type_coercion_demoFunction · 0.45

Calls 6

sumMethod · 0.80
as_refMethod · 0.45
takeMethod · 0.45
skipMethod · 0.45
iterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected