liukun4515 commented on a change in pull request #1408:
URL: https://github.com/apache/arrow-datafusion/pull/1408#discussion_r771180890
##########
File path: datafusion/src/physical_plan/expressions/average.rs
##########
@@ -102,7 +114,14 @@ impl AggregateExpr for Avg {
}
fn field(&self) -> Result<Field> {
- Ok(Field::new(&self.name, DataType::Float64, true))
+ Ok(Field::new(&self.name, self.data_type.clone(), true))
+ }
+
+ fn create_accumulator(&self) -> Result<Box<dyn Accumulator>> {
+ Ok(Box::new(AvgAccumulator::try_new(
+ // avg is f64 or decimal
+ &self.data_type,
Review comment:
The result type of phy expr(sum/avg) is same with each Accumulator, and
it was decided by `sum_return_type` and `avg_return_type`.
If the column is decimal(8,2), the avg of this column must be less than
`10^10-1`, but we need more digits to represent the decimal part. For example,
The avg of `3,4,6` is `4.333333.....`, we should increase the scale part.
For the sum agg, we just should increase the precision part, and the rule of
adding `10` to precision is spark coercion rule for sum decimal. We can have
our rules for decimal if we want.
@alamb
We can just follow the spark now, and change the rules if we want to define
own rules.
--
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]