aggregate
The aggregate operator takes an input array, list of one or more aggregate function calls, and (optionally) a list of dimensions along which the aggregates are to be computed. It returns an array containing the computed aggregate values.
Synopsis
aggregate(array, aggregate_1
         [, aggregate_2,... aggregate_N]
         [,dimension_1, dimension_2,...]);
Summary
SciDB aggregates are functions of several values that produce a scalar value. Used together with the aggregate and redimension operators, they compute data aggregations, optionally grouped along a specified dimension or dimensions.
The aggregate operator takes the following arguments:Â
- Array name. The aggregation is performed on data from the named array.
- Aggregating functions. This is the aggregation to perform. You can list one or more aggregating functions.
- Dimensions (optional). Most aggregates allow aggregation along one or more dimensions. You can list zero or more dimensions along which to perform the aggregation.
The aggregate operator returns a SciDB array containing the aggregation result as a new attribute. The name of this attribute is constructed as follows: inputAttribute_aggregateFunction, where:
- inputAttribute is the name of the aggregated attribute.
- aggregateFunction is the name of the aggregate function called.
For example, assume an array A with an attribute sales. The name for the result attribute of aggregate(A,sum(sales)); is 'sales_sum'.
Example
To create a sparse array and then performs some aggregation on it, do the following:
Create an array containing values along the diagonal, and empty cells everywhere else:
AFL% store(redimension ( apply ( build(<val:double>[i1=0:3; j1=0:3], i1), i, iif(i1=j1, i1,null), j, iif(i1=j1,i1,null)), <val:double>[i=0:3; j=0:3]),A); {i,j} val {0,0} 0 {1,1} 1 {2,2} 2 {3,3} 3
Use the aggregate operator to count the number of non-empty cells:
AFL% aggregate(A, count(val)); {i} val_count {0} 4
Â
Use the aggregate operator to calculate the sum of all cells in the array:
AFL% aggregate(A, sum(val)); {i} val_sum {0} 6
Â