Jefffrey commented on code in PR #19706:
URL: https://github.com/apache/datafusion/pull/19706#discussion_r2674557349
##########
datafusion/functions-aggregate/src/variance.rs:
##########
@@ -581,6 +616,71 @@ impl GroupsAccumulator for VarianceGroupsAccumulator {
}
}
+#[derive(Debug)]
+pub struct DistinctVarianceAccumulator {
+ distinct_values: GenericDistinctBuffer<Float64Type>,
+ stat_type: StatsType,
+}
+
+impl DistinctVarianceAccumulator {
+ pub fn new(stat_type: StatsType) -> Self {
+ Self {
+ distinct_values:
GenericDistinctBuffer::<Float64Type>::new(DataType::Float64),
+ stat_type,
+ }
+ }
+}
+
+impl Accumulator for DistinctVarianceAccumulator {
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ let cast_values = cast(&values[0], &DataType::Float64)?;
+ self.distinct_values
+ .update_batch(vec![cast_values].as_ref())
+ }
+
+ fn evaluate(&mut self) -> Result<ScalarValue> {
+ let values = std::mem::take(&mut self.distinct_values.values)
+ .iter()
+ .map(|v| v.0)
+ .collect::<Vec<_>>();
Review Comment:
```suggestion
let values = self.distinct_values.values
.iter()
.map(|v| v.0)
.collect::<Vec<_>>();
```
We can't take memory here, see related issues/PRs:
- https://github.com/apache/datafusion/issues/19612
- https://github.com/apache/datafusion/pull/19278
##########
datafusion/functions-aggregate/src/variance.rs:
##########
@@ -581,6 +616,71 @@ impl GroupsAccumulator for VarianceGroupsAccumulator {
}
}
+#[derive(Debug)]
+pub struct DistinctVarianceAccumulator {
+ distinct_values: GenericDistinctBuffer<Float64Type>,
+ stat_type: StatsType,
+}
+
+impl DistinctVarianceAccumulator {
+ pub fn new(stat_type: StatsType) -> Self {
+ Self {
+ distinct_values:
GenericDistinctBuffer::<Float64Type>::new(DataType::Float64),
+ stat_type,
+ }
+ }
+}
+
+impl Accumulator for DistinctVarianceAccumulator {
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ let cast_values = cast(&values[0], &DataType::Float64)?;
+ self.distinct_values
+ .update_batch(vec![cast_values].as_ref())
+ }
+
+ fn evaluate(&mut self) -> Result<ScalarValue> {
+ let values = std::mem::take(&mut self.distinct_values.values)
+ .iter()
+ .map(|v| v.0)
+ .collect::<Vec<_>>();
+
+ let count = match self.stat_type {
+ StatsType::Sample => {
+ if !values.is_empty() {
+ values.len() - 1
+ } else {
+ values.len()
Review Comment:
```suggestion
0
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]