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

Method state

datafusion/functions-aggregate/src/median.rs:258–281  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

256
257impl<T: ArrowNumericType> Accumulator for MedianAccumulator<T> {
258 fn state(&mut self) -> Result<Vec<ScalarValue>> {
259 // Convert `all_values` to `ListArray` and return a single List ScalarValue
260
261 // Build offsets
262 let offsets =
263 OffsetBuffer::new(ScalarBuffer::from(vec![0, self.all_values.len() as i32]));
264
265 // Build inner array
266 let values_array = PrimitiveArray::<T>::new(
267 ScalarBuffer::from(std::mem::take(&mut self.all_values)),
268 None,
269 )
270 .with_data_type(self.data_type.clone());
271
272 // Build the result list array
273 let list_array = ListArray::new(
274 Arc::new(Field::new_list_field(self.data_type.clone(), true)),
275 offsets,
276 Arc::new(values_array),
277 None,
278 );
279
280 Ok(vec![ScalarValue::List(Arc::new(list_array))])
281 }
282
283 fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
284 let values = values[0].as_primitive::<T>();

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
with_data_typeMethod · 0.80
take_neededMethod · 0.80
flattenMethod · 0.80
cloneMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected