package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Granary_ivm.AggregateSource

Incremental grouped aggregation over Z-sets (#417 Phase 2).

Maintains a SUM-style aggregate per group: each input element contributes measure element * weight to its group's running value, and the group's existence is tracked by its total weight (so COUNT is the special case measure = fun _ -> 1). Given an input delta, step returns the output delta that retracts each changed group's old (group, value) row and inserts its new one — keeping the result relation current without rescanning the input. A group's row is present iff its total weight is > 0, and each present group yields exactly one output row.

The measure is additive, which is what makes the running total maintainable from a delta (this covers COUNT, SUM, and AVG as sum-with-count). Order-sensitive aggregates (MIN/MAX) cannot be expressed this way — a retraction can lower the current extremum, which needs the full group, not a running scalar — and are out of scope here.

Sourcemodule type SPEC = sig ... end

What to aggregate: the input/output Z-set domains, the grouping key, the per-element measure, and how to render a (group, value) result row.

Sourcemodule Make (S : SPEC) : sig ... end

Make (S) builds an incremental grouped-aggregate operator for spec S.