alamb commented on code in PR #6837:
URL: https://github.com/apache/arrow-datafusion/pull/6837#discussion_r1252006197
##########
datafusion/physical-expr/src/aggregate/median.rs:
##########
@@ -111,13 +112,28 @@ impl PartialEq<dyn Any> for Median {
/// The intermediate state is represented as a List of those scalars
struct MedianAccumulator {
data_type: DataType,
+ batches: Vec<ArrayRef>,
all_values: Vec<ScalarValue>,
}
+fn to_scalar_values(arrays: &[ArrayRef]) -> Result<Vec<ScalarValue>> {
+ let num_values: usize = arrays.iter().map(|a| a.len()).sum();
+ let mut all_values = Vec::with_capacity(num_values);
+
+ for array in arrays {
+ for index in 0..array.len() {
+ all_values.push(ScalarValue::try_from_array(&array, index)?);
+ }
+ }
+
+ Ok(all_values)
+}
+
impl Accumulator for MedianAccumulator {
fn state(&self) -> Result<Vec<ScalarValue>> {
- let state =
- ScalarValue::new_list(Some(self.all_values.clone()),
self.data_type.clone());
+ let all_values = to_scalar_values(&self.batches)?;
+ let state = ScalarValue::new_list(Some(all_values),
self.data_type.clone());
Review Comment:
Maybe @Dandandan was suggesting
```rust
impl ScalarValue {
...
List(ArrayRef)
...
}
```
In general this would work well with the approach @tustvold is working on
upstream in arrow-rs with `Datum` --
https://github.com/apache/arrow-rs/pull/4393
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]