Function - (Aggregate | Aggregation | Summary)

> Code - (Programming|Computer) Language > (Function | Operator | Map | Mapping | Transformation | Method | Rule | Task | Subroutine)

1 - About

Aggregate functions return a single value, calculated from values that are in a aggregation relationship (ie a collection such as an array)

You aggregate generally over additive numeric data grouped by class attribute


3 - List

Example of aggregate functions:

  • AVG() - Returns the average value
  • COUNT() - Returns the number of rows
  • FIRST() - Returns the first value
  • LAST() - Returns the last value
  • MAX() - Returns the largest value
  • MIN() - Returns the smallest value
  • SUM() - Returns the sum

4 - Implementation

4.1 - Mutative operation

Mutative accumulation for a sum

int sum = 0;
for (int x : numbers) {
   sum += x;

4.2 - Reduction operation

They are implemented as reduction operation

4.3 - Partition

Some operations like AVG are not partitionable. It is not valid to compute them on partitioned data because they are not commutative and associative).

You can still compute partial aggregates by transforming the non-commutative and associative function by commutative and associative function and, then roll them up. For example if you want to compute AVG(x) you can expand to SUM(x) / COUNT(x), and compute partition SUM(x) and COUNT(X) on each partition then sum them using SUM.