Skip to main content

DecimalTrack

Struct DecimalTrack 

Source
pub struct DecimalTrack {
    pub scale: u8,
    pub sum: i128,
    pub min: i128,
    pub max: i128,
    pub first: i128,
    pub last: i128,
    pub overflow: bool,
}
Expand description

The exact half of an accumulator, allocated only for decimal columns.

Boxed behind an Option so a float column pays eight bytes for it and nothing else — a group-by over a high-cardinality tag holds one accumulator per (group, field), and making every one of them 128 bytes wider to support a column type it does not have is a cost the gateway would feel.

Fields§

§scale: u8

The scale everything tracked here is expressed at.

§sum: i128

Running total.

§min: i128

Smallest mantissa seen.

§max: i128

Largest mantissa seen.

§first: i128

Mantissa at the earliest timestamp.

§last: i128

Mantissa at the latest timestamp.

§overflow: bool

A sum or a rescale needed more than 38 significant digits. The affected results are NULL: a number that is not the answer is worse than no number.

Implementations§

Source§

impl DecimalTrack

Source

pub fn new(scale: u8) -> Self

An empty track at scale.

Source

pub fn widen_to(&mut self, scale: u8)

Re-express everything tracked so far at a wider scale.

Source

pub fn align(&mut self, mantissa: i128, scale: u8) -> Option<i128>

Bring an incoming mantissa to the track’s scale, widening the track if the incoming value is finer. Both directions are exact.

Returns None when the alignment would overflow 38 digits; the caller sets overflow.

Source

pub fn sum_result(&self) -> AggResult

The sum, or Null if it overflowed 38 digits.

Source

pub fn avg_result(&self, count: u64) -> AggResult

The mean, carried to AVG_EXTRA_SCALE extra digits and rounded half away from zero. See that constant for why this is the one aggregate that rounds.

Source

pub fn at(&self, mantissa: i128) -> AggResult

One tracked mantissa as a result.

Trait Implementations§

Source§

impl Clone for DecimalTrack

Source§

fn clone(&self) -> DecimalTrack

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DecimalTrack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more