thinh2 commented on code in PR #19706:
URL: https://github.com/apache/datafusion/pull/19706#discussion_r2675026926


##########
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:
   thanks for reviewing @Jefffrey, I have updated my code. 



-- 
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]

Reply via email to