Aggregations

Every aggregate of MobilityDB, such as tCount, tSum or extent, is called by the same name in every engine, with one exception. Eleven aggregates share their name with a function: tMin, tMax, merge, appendInstant, appendSequence, sameAlignment, tAnd, tOr, setUnion, spanUnion and spansetUnion. PostgreSQL lets an aggregate and a function share a name, and MobilityDB calls these aggregates by it. DuckDB, Apache Spark and Apache Flink hold one function per name, and call them by the name with Agg: tMinAgg, mergeAgg, setUnionAgg, and so on (the section called “Names the Engines Own”).

An aggregate computes its result in up to three steps, each a function named after the aggregate and the step. The transition function <aggregate>Transition adds one value to a running state, the combine function <aggregate>Combine joins two states computed in parallel, and the final function <aggregate>Final turns the state into the result. The combine and final steps are optional: extent has no final function, since its state is already its result, and the append aggregates have no combine function, since they add their values in time order. A query never calls these functions; each engine builds the aggregate from them.

The transition function takes the state and a value, and has one version per type of value, as the aggregate has: tMinTransition takes a tint, a tbigint, a tfloat or a ttext. The combine and final functions take only states, and a state knows the type of the values it holds, so each is one function per aggregate: tMinCombine combines the states of the temporal minimum of every type of value. In PostgreSQL, where a final function declares the type it returns, the final function is declared once per type of value with FINALFUNC_EXTRA, as tMinFinal(internal, tint) returning a tint, all its versions running the same code. In Spark and Flink each aggregate is one object, which chooses its transition function from the type of the value.

The following table lists every aggregate and its functions; a dash (—) marks a step the aggregate does not have.

CategoryTransitionCombineFinal
CounttCountTransitiontCountCombinetCountFinal
 wCountTransitionwCountCombinewCountFinal
SumtSumTransitiontSumCombinetSumFinal
 wSumTransitionwSumCombinewSumFinal
AveragetAvgTransitiontAvgCombinetAvgFinal
 wAvgTransitionwAvgCombinewAvgFinal
Minimum / maximumtMinTransitiontMinCombinetMinFinal
 tMaxTransitiontMaxCombinetMaxFinal
 wMinTransitionwMinCombinewMinFinal
 wMaxTransitionwMaxCombinewMaxFinal
BooleantAndTransitiontAndCombinetAndFinal
 tOrTransitiontOrCombinetOrFinal
CentroidtCentroidTransitiontCentroidCombinetCentroidFinal
Point cloudtnpointsTransitiontnpointsCombinetnpointsFinal
 tdensityTransitiontdensityCombinetdensityFinal
Bounding boxextentTransitionextentCombine—
UnionsetUnionTransitionsetUnionCombinesetUnionFinal
 spanUnionTransitionspanUnionCombinespanUnionFinal
 spansetUnionTransitionspansetUnionCombinespansetUnionFinal
MergemergeTransitionmergeCombinemergeFinal
AppendappendInstantTransition—appendInstantFinal
 appendSequenceTransition—appendSequenceFinal
RasterrasterUnionTransitionrasterUnionCombinerasterUnionFinal
 sameAlignmentTransitionsameAlignmentCombinesameAlignmentFinal
 summaryStatsAggTransitionsummaryStatsAggCombinesummaryStatsAggFinal