Skip to main content

scalar

Function scalar 

Source
pub fn scalar(schema: &SeriesSchema, series: &[Series]) -> Result<Series>
Expand description

scalar(v): the value of the only float sample present at each point, NaN otherwise.

Native histogram samples are ignored, as Prometheus’ funcScalar ignores them: they hold no float value, and they are not an element either, so they never make a point hold more than one sample. A point whose only sample is a histogram therefore answers NaN, a histogram beside one float answers that float, and two floats answer NaN.

A scalar holds a value at every point of the grid, so its value array is written where the input is read rather than staged and rebuilt: the one buffer of values becomes the result’s array, and the counts that decide between a value and a NaN are dropped before it is handed over. Building it therefore costs one f64 and one count per point and nothing else per point – no optional value, no row index, no second copy of the answer – which is what the caller reserves for it.