alamb commented on code in PR #5973:
URL: https://github.com/apache/arrow-datafusion/pull/5973#discussion_r1164540227


##########
datafusion/physical-expr/src/aggregate/average.rs:
##########
@@ -298,16 +305,40 @@ impl RowAccumulator for AvgRowAccumulator {
     }
 
     fn evaluate(&self, accessor: &RowAccessor) -> Result<ScalarValue> {
-        assert_eq!(self.sum_datatype, DataType::Float64);
-        Ok(match accessor.get_u64_opt(self.state_index()) {
-            None => ScalarValue::Float64(None),
-            Some(0) => ScalarValue::Float64(None),
-            Some(n) => ScalarValue::Float64(
-                accessor
-                    .get_f64_opt(self.state_index() + 1)
-                    .map(|f| f / n as f64),
-            ),
-        })
+        match self.sum_datatype {
+            DataType::Decimal128(p, s) => {
+                match accessor.get_u64_opt(self.state_index()) {
+                    None => Ok(ScalarValue::Decimal128(None, p, s)),
+                    Some(0) => Ok(ScalarValue::Decimal128(None, p, s)),

Review Comment:
   Why do we translate `0` --> `null` here? (it is also done for Float64 
below)? 
   
   I see you are just following the existing pattern, but it seems like this 
could be incorrect?
   
   Maybe we could add a test that calls `AVG` on (`-1` and `1`) to see if we 
get `0` or `NULL`



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

Reply via email to