MCPcopy Create free account
hub / github.com/apache/datafusion / avg

Method avg

datafusion/functions-aggregate-common/src/utils.rs:157–176  ·  view source on GitHub ↗
(&self, sum: T::Native, count: T::Native)

Source from the content-addressed store, hash-verified

155 /// * count: total count, stored as a i128/i256 (*NOT* a Decimal128/Decimal256 value)
156 #[inline(always)]
157 pub fn avg(&self, sum: T::Native, count: T::Native) -> Result<T::Native> {
158 if let Ok(value) = sum.mul_checked(self.target_mul.div_wrapping(self.sum_mul)) {
159 let new_value = value.div_wrapping(count);
160
161 let validate = T::validate_decimal_precision(
162 new_value,
163 self.target_precision,
164 self.target_scale,
165 );
166
167 if validate.is_ok() {
168 Ok(new_value)
169 } else {
170 exec_err!("Arithmetic Overflow in AvgAccumulator")
171 }
172 } else {
173 // can't convert the lit decimal to the returned data type
174 exec_err!("Arithmetic Overflow in AvgAccumulator")
175 }
176 }
177}
178
179/// Generic way to collect distinct values for accumulators.

Callers 3

evaluateMethod · 0.80
evaluateMethod · 0.80

Calls 3

mul_checkedMethod · 0.80
is_okMethod · 0.45

Tested by

no test coverage detected