Struct datafusion_physical_expr::aggregate::utils::DecimalAverager
source · pub struct DecimalAverager<T>where
T: DecimalType,{ /* private fields */ }
Expand description
Computes averages for Decimal128
/Decimal256
values, checking for overflow
This is needed because different precisions for Decimal128/Decimal256 can store different ranges of values and thus sum/count may not fit in the target type.
For example, the precision is 3, the max of value is 999
and the min
value is -999
Implementations§
source§impl<T> DecimalAverager<T>where
T: DecimalType,
impl<T> DecimalAverager<T>where
T: DecimalType,
sourcepub fn try_new(
sum_scale: i8,
target_precision: u8,
target_scale: i8,
) -> Result<DecimalAverager<T>, DataFusionError>
pub fn try_new( sum_scale: i8, target_precision: u8, target_scale: i8, ) -> Result<DecimalAverager<T>, DataFusionError>
Create a new DecimalAverager
:
- sum_scale: the scale of
sum
values passed toSelf::avg
- target_precision: the output precision
- target_scale: the output scale
Errors if the resulting data can not be stored
sourcepub fn avg(
&self,
sum: <T as ArrowPrimitiveType>::Native,
count: <T as ArrowPrimitiveType>::Native,
) -> Result<<T as ArrowPrimitiveType>::Native, DataFusionError>
pub fn avg( &self, sum: <T as ArrowPrimitiveType>::Native, count: <T as ArrowPrimitiveType>::Native, ) -> Result<<T as ArrowPrimitiveType>::Native, DataFusionError>
Returns the sum
/count
as a i128/i256 Decimal128/Decimal256 with
target_scale and target_precision and reporting overflow.
- sum: The total sum value stored as Decimal128 with sum_scale
(passed to
Self::try_new
) - count: total count, stored as a i128/i256 (NOT a Decimal128/Decimal256 value)
Auto Trait Implementations§
impl<T> Freeze for DecimalAverager<T>
impl<T> RefUnwindSafe for DecimalAverager<T>
impl<T> Send for DecimalAverager<T>
impl<T> Sync for DecimalAverager<T>
impl<T> Unpin for DecimalAverager<T>
impl<T> UnwindSafe for DecimalAverager<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more