yahoNanJing commented on code in PR #5973:
URL: https://github.com/apache/arrow-datafusion/pull/5973#discussion_r1164923140
##########
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:
Hi @alamb, the value at the `state_index` is for the count rather than the
sum. When the count is 0, for the average, it should be 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]