Cloud Datastore Client - Class Aggregation (1.26.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
aliasstring

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 returnsINF.Sum of data which containsNaN returnsNaN.Non numeric values are ignored.

Parameter
NameDescription
propertystring

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 returnnull.Average of numbers exceeding max float value returnsINF.Average of data which containsNaN returnsNaN.Non numeric values are ignored.

Parameter
NameDescription
propertystring

The relative path of the field to aggregate upon.

Returns
TypeDescription
Google\Cloud\Datastore\Query\Aggregation

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-24 UTC.