Rachelint commented on code in PR #14399:
URL: https://github.com/apache/datafusion/pull/14399#discussion_r1938281192


##########
datafusion/functions-aggregate/src/median.rs:
##########
@@ -242,14 +242,26 @@ impl<T: ArrowNumericType> Debug for MedianAccumulator<T> {
 
 impl<T: ArrowNumericType> Accumulator for MedianAccumulator<T> {
     fn state(&mut self) -> Result<Vec<ScalarValue>> {
-        let all_values = self
-            .all_values
-            .iter()
-            .map(|x| ScalarValue::new_primitive::<T>(Some(*x), 
&self.data_type))
-            .collect::<Result<Vec<_>>>()?;
+        // Convert `all_values` to `ListArray` and return a single List 
ScalarValue
 
-        let arr = ScalarValue::new_list_nullable(&all_values, &self.data_type);
-        Ok(vec![ScalarValue::List(arr)])
+        // Build offsets
+        let offsets =
+            OffsetBuffer::new(ScalarBuffer::from(vec![0, self.all_values.len() 
as i32]));
+
+        // Build inner array
+        let values_array =
+            
PrimitiveArray::<T>::new(ScalarBuffer::from(self.all_values.clone()), None)

Review Comment:
   Seems we can take `all_values` directly, and reduce the allocation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to