- HTTP request
- Path parameters
- Request body
- Response body
- Authorization scopes
- AggregationQuery
- Aggregation
- Count
- Sum
- Avg
- AggregationResultBatch
- AggregationResult
- Try it!
Runs an aggregation query.
HTTP request
POST https://datastore.googleapis.com/v1/projects/{projectId}:runAggregationQuery
The URL uses gRPC Transcoding syntax.
Path parameters
Parameters | |
---|---|
projectId |
Required. The ID of the project against which to make the request. |
Request body
The request body contains data with the following structure:
JSON representation |
---|
{ "databaseId": string, "partitionId": { object ( |
Fields | |
---|---|
databaseId |
The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database. |
partitionId |
Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID. |
readOptions |
The options for this query. |
explainOptions |
Optional. Explain options for the query. If set, additional query statistics will be returned. If not, only query results will be returned. |
Union field query_type . The type of query. query_type can be only one of the following: |
|
aggregationQuery |
The query to run. |
gqlQuery |
The GQL query to run. This query must be an aggregation query. |
Response body
The response for Datastore.RunAggregationQuery
.
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "batch": { object ( |
Fields | |
---|---|
batch |
A batch of aggregation results. Always present. |
query |
The parsed form of the |
transaction |
The identifier of the transaction that was started as part of this projects.runAggregationQuery request. Set only when A base64-encoded string. |
explainMetrics |
Query explain metrics. This is only present when the |
Authorization scopes
Requires one of the following OAuth scopes:
https://www.googleapis.com/auth/datastore
https://www.googleapis.com/auth/cloud-platform
For more information, see the Authentication Overview.
AggregationQuery
Datastore query for running an aggregation over a Query
.
JSON representation |
---|
{ "aggregations": [ { object ( |
Fields | |
---|---|
aggregations[] |
Optional. Series of aggregations to apply over the results of the Requires:
|
Union field query_type . The base query to aggregate over. query_type can be only one of the following: |
|
nestedQuery |
Nested query for aggregation |
Aggregation
Defines an aggregation that produces a single result.
JSON representation |
---|
{ "alias": string, // Union field |
Fields | |
---|---|
alias |
Optional. Optional name of the property to store the result of the aggregation. If not provided, Datastore will pick a default name following the format
becomes:
Requires:
|
Union field operator . The type of aggregation to perform, required. operator can be only one of the following: |
|
count |
Count aggregator. |
sum |
Sum aggregator. |
avg |
Average aggregator. |
Count
Count of entities that match the query.
The COUNT(*)
aggregation function operates on the entire entity so it does not require a field reference.
JSON representation |
---|
{ "upTo": string } |
Fields | |
---|---|
upTo |
Optional. Optional constraint on the maximum number of entities to count. This provides a way to set an upper bound on the number of entities to scan, limiting latency, and cost. Unspecified is interpreted as no bound. If a zero value is provided, a count result of zero should always be expected. High-Level Example:
Requires:
|
Sum
Sum of the values of the requested property.
Only numeric values will be aggregated. All non-numeric values including
NULL
are skipped.If the aggregated values contain
NaN
, returnsNaN
. Infinity math follows IEEE-754 standards.If the aggregated value set is empty, returns 0.
Returns a 64-bit integer if all aggregated numbers are integers and the sum result does not overflow. Otherwise, the result is returned as a double. Note that even if all the aggregated values are integers, the result is returned as a double if it cannot fit within a 64-bit signed integer. When this occurs, the returned value will lose precision.
When underflow occurs, floating-point aggregation is non-deterministic. This means that running the same query repeatedly without any changes to the underlying values could produce slightly different results each time. In those cases, values should be stored as integers over floating-point numbers.
JSON representation |
---|
{
"property": {
object ( |
Fields | |
---|---|
property |
The property to aggregate on. |
Avg
Average of the values of the requested property.
Only numeric values will be aggregated. All non-numeric values including
NULL
are skipped.If the aggregated values contain
NaN
, returnsNaN
. Infinity math follows IEEE-754 standards.If the aggregated value set is empty, returns
NULL
.Always returns the result as a double.
JSON representation |
---|
{
"property": {
object ( |
Fields | |
---|---|
property |
The property to aggregate on. |
AggregationResultBatch
A batch of aggregation results produced by an aggregation query.
JSON representation |
---|
{ "aggregationResults": [ { object ( |
Fields | |
---|---|
aggregationResults[] |
The aggregation results for this batch. |
moreResults |
The state of the query after the current batch. Only COUNT(*) aggregations are supported in the initial launch. Therefore, expected result type is limited to |
readTime |
Read timestamp this batch was returned from. In a single transaction, subsequent query result batches for the same query can have a greater timestamp. Each batch's read timestamp is valid for all preceding batches. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: |
AggregationResult
The result of a single bucket from a Datastore aggregation query.
The keys of aggregateProperties
are the same for all results in an aggregation query, unlike entity queries which can have different fields present for each result.
JSON representation |
---|
{
"aggregateProperties": {
string: {
object ( |
Fields | |
---|---|
aggregateProperties |
The result of the aggregation functions, ex: The key is the An object containing a list of |