Reference documentation and code samples for the Cloud Datastore Client class Aggregation.
Represents Aggregation properties.
Example:
$count = Aggregation::count();
$count->alias('count');
$count->limit(100);
echo json_encode($count->getProps());
Aggregations considers non existing property name as an empty query set
Namespace
Google \ Cloud \ Datastore \ QueryMethods
alias
Set the aggregation alias.
Example:
$count = Aggregation->count();
$count->alias('total');
echo $count->props()['count']['alias'];
Parameter | |
---|---|
Name | Description |
alias |
string
The alias for aggregation. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Query\Aggregation |
getProps
Get the array representation for the aggregation.
Returns | |
---|---|
Type | Description |
array |
static::count
Creates count aggregation properties.
Example:
$count = Aggregation::count();
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Query\Aggregation |
static::sum
Creates sum aggregation properties.
Example:
$sum = Aggregate::sum('property_to_aggregate_upon');
Result of SUM aggregation can be a integer or a float.
Sum of integers which exceed maxinum integer value returns a float.
Sum of numbers exceeding max float value returns INF
.
Sum of data which contains NaN
returns NaN
.
Non numeric values are ignored.
Parameter | |
---|---|
Name | Description |
property |
string
The relative path of the field to aggregate upon. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Query\Aggregation |
static::avg
Creates average aggregation properties.
Example:
$avg = Aggregate::avg('property_to_aggregate_upon');
Result of AVG aggregation can be a float or a null.
Average of empty valid data set return null
.
Average of numbers exceeding max float value returns INF
.
Average of data which contains NaN
returns NaN
.
Non numeric values are ignored.
Parameter | |
---|---|
Name | Description |
property |
string
The relative path of the field to aggregate upon. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Query\Aggregation |