Skip to main content

aggregate_expr

Function aggregate_expr 

Source
fn aggregate_expr(
    context: &Context<'_>,
    aggregate: &AggregateExpr,
) -> Result<NativeNode>
Expand description

Compiles an aggregation into an aggregate node over the expression it groups.

The aggregators that fold a group’s values into one value per grid point bind to an aggregate node: sum, avg, count, min, max, group, stddev, stdvar and quantile. The runtime validates whether the resulting tree can execute.

The rest of the parser’s aggregates are a different shape and bind as a vector operation (vector_aggregate) rather than as a kind that would compute something else: topk, bottomk, limitk and limit_ratio select some of the input’s series, so they do not report one value per group per grid point, and count_values writes one output label per distinct value rather than folding a group’s values at all.

The grouping is bound in the tree’s own terms, because by and without are not each other’s inverse: by(job) keeps job and drops every other label, while without(instance) keeps every label it does not name and drops __name__ as well, so a list of the surviving labels could not say the same thing. A bare sum(x) groups by no label at all, which is Prometheus’s reading of “no modifier”: every label is dropped, __name__ included, and every series of the input falls into one group.

The stage is [AggregateStage::Complete], which says that every contribution to each group is in this execution’s input. The module documentation says what keeping that claim costs a caller.