viirya commented on code in PR #261:
URL: 
https://github.com/apache/arrow-datafusion-comet/pull/261#discussion_r1561793369


##########
core/src/execution/datafusion/expressions/avg.rs:
##########
@@ -176,9 +176,15 @@ impl Accumulator for AvgAccumulator {
     }
 
     fn evaluate(&mut self) -> Result<ScalarValue> {
-        Ok(ScalarValue::Float64(
-            self.sum.map(|f| f / self.count as f64),
-        ))
+        if self.count == 0 {
+            // If all input are nulls, count will be 0 and we will get null 
after the division.
+            // This is consistent with Spark Average implementation.
+            return Ok(ScalarValue::Float64(None));
+        } else {
+            Ok(ScalarValue::Float64(
+                self.sum.map(|f| f / self.count as f64),
+            ))

Review Comment:
   Actually the `GroupsAccumulator` below has correctly implemented this 
behavior. Only `AvgAccumulator` has this issue.



-- 
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...@arrow.apache.org

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

Reply via email to