Aggregation functions

Overview

Functions are used when constructing the aggr parameter of a query for an aggregation fetch from a dynamic class collection.

The very fact of constructing an aggregation query obliges the use of at least one aggregation function.

Filter construction order

The value of the aggr parameter when constructing an aggregation query is an object whose keys are the returned fields, each of which contains an aggregation value. As the value of these keys you should specify a list, the first element of which is one of the aggregation functions, and the other elements are the parameters of this function.

For example:
["count",1]

["sum",["property","pint"]]
For example:
["sum",["%",["-",["property","pint"],1],10]]

In the general case, the value of the aggr parameter may look like this:

.

{
  "x": ["sum",["//",["-",["property","pint"],1],10]],
  "any": ["or",["property","pbool"]]
}

List of supported functions

All functions apply to values in a group with the same base.

  • count/1 - counting the number of elements in the group. Parameter - arbitrary value.

  • sum/1 - summarizing a numeric value. The parameter is usually the function ["property",FIELDNAME]. In some cases it may be useful to generate by the condition 0 or 1.

  • min/1 - calculation of the minimum value.

  • max/1 - calculation of the maximum value.

  • avg/1 - calculation of the average value. To construct a weighted sum, you can pass a function from the value as a parameter, e.g. multiplication by a weighting factor, which is also calculated as a function.

  • and/1 - Boolean multiplication of values.

  • or/1 - Boolean addition of values.

  • join/2 - meshing of strings through a delimiter. The first argument is the delimiter (expressed as a constant or function), the second element is the value (expressed as an arbitrary function).