Cloud Datastore Client - Class Aggregation (1.29.2)

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
Name
Description
alias
string

The alias for aggregation.

Returns
Type
Description

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

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

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
Design a Mobile Site
View Site in Mobile | Classic
Share by: