Cloud Datastore Client - Class Aggregation (1.25.0)

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 \ Query

Methods

alias

Set the aggregation alias.

Example:

$count = Aggregation->count();
$count->alias('total');

echo $count->props()['count']['alias'];
Parameter
NameDescription
alias string

The alias for aggregation.

Returns
TypeDescription
Google\Cloud\Datastore\Query\Aggregation

getProps

Get the array representation for the aggregation.

Returns
TypeDescription
array

static::count

Creates count aggregation properties.

Example:

$count = Aggregation::count();
Returns
TypeDescription
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
NameDescription
property string

The relative path of the field to aggregate upon.

Returns
TypeDescription
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
NameDescription
property string

The relative path of the field to aggregate upon.

Returns
TypeDescription
Google\Cloud\Datastore\Query\Aggregation