Aggregations and Calculations#
Concourse provides built-in aggregation functions for performing
calculations across record data. All aggregations are accessed
through the calculate() method on the Concourse client.
Available Functions#
count#
Count the number of values stored for a key. Use the special
$id$ key to count matching records instead of values.
1 2 3 4 5 6 7 8 9 10 | |
Counting Records#
To count the number of records matching a criteria (equivalent
to SQL’s SELECT COUNT(*)), use the $id$ intrinsic key:
1 2 3 | |
1 2 | |
sum#
Compute the sum of all numeric values stored for a key.
1 2 3 4 5 | |
average#
Compute the arithmetic mean of all numeric values stored for a key.
1 2 3 4 5 | |
min#
Find the minimum numeric value stored for a key.
1 2 3 4 5 | |
max#
Find the maximum numeric value stored for a key.
1 2 3 4 5 | |
Filtering with Criteria#
All aggregation functions accept an optional CCL string or
Criteria object to filter which records are included in the
calculation.
CCL String#
1 2 3 | |
Criteria Object#
1 2 3 4 5 6 7 8 | |
Filtering by Records#
You can limit calculations to a specific set of records:
1 2 3 | |
Or a single record (useful when a key has multiple values):
1 2 3 | |
Time-Aware Aggregations#
All aggregation functions support a Timestamp parameter to
perform calculations on historical data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Functions in Conditions#
In addition to the calculate() API, aggregation functions can
be used directly inside CCL conditions
as comparison values. This lets you write queries that filter
records based on how their values compare to an aggregate.
Call Syntax#
Use a function call on the value side of a condition:
1 2 3 | |
Pipe Syntax#
Use the | operator on the key side:
1 2 | |
In CaSH#
1 2 3 | |
See the CCL Reference for the full function syntax.
Summary#
| Function | Description | Return Type |
|---|---|---|
count |
Number of values | long |
sum |
Total of numeric values | Number |
average |
Arithmetic mean | Number |
min |
Minimum value | Number |
max |
Maximum value | Number |
All functions support these parameter combinations:
key— across all recordskey, records— in specific recordskey, record— in a single recordkey, ccl— in records matching a CCL querykey, criteria— in records matching a Criteria
Each combination also accepts an optional Timestamp for
historical calculations.