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

Method update_batch

datafusion-examples/examples/udf/simple_udaf.rs:93–109  ·  view source on GitHub ↗

DataFusion calls this function to update the accumulator's state for a batch of inputs rows. In this case the product is updated with values from the first column and the count is updated based on the row count

(&mut self, values: &[ArrayRef])

Source from the content-addressed store, hash-verified

91 // of inputs rows. In this case the product is updated with values from the first column
92 // and the count is updated based on the row count
93 fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
94 if values.is_empty() {
95 return Ok(());
96 }
97 let arr = &values[0];
98 (0..arr.len()).try_for_each(|index| {
99 let v = ScalarValue::try_from_array(arr, index)?;
100
101 if let ScalarValue::Float64(Some(value)) = v {
102 self.prod *= value;
103 self.n += 1;
104 } else {
105 unreachable!("")
106 }
107 Ok(())
108 })
109 }
110
111 // Optimization hint: this trait also supports `update_batch` and `merge_batch`,
112 // that can be used to perform these operations on arrays instead of single values.

Callers

nothing calls this directly

Calls 2

is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected