Package com.google.cloud.datastore
Class AggregationQuery
- java.lang.Object
-
- com.google.cloud.datastore.Query<AggregationResults>
-
- com.google.cloud.datastore.AggregationQuery
-
- All Implemented Interfaces:
Serializable
public class AggregationQuery extends Query<AggregationResults>
An implementation of a Google Cloud Datastore Query that returnsAggregationResults
, It can be constructed by providing a nested query (StructuredQuery
orGqlQuery
) to run the aggregations on and a set ofAggregation
.StructuredQuery
example:EntityQuery selectAllQuery = Query.newEntityQueryBuilder() .setKind("Task") .build(); AggregationQuery aggregationQuery = Query.newAggregationQueryBuilder() .addAggregation(count().as("total_count")) .over(selectAllQuery) .build(); AggregationResults aggregationResults = datastore.runAggregation(aggregationQuery); for (AggregationResult aggregationResult : aggregationResults) { System.out.println(aggregationResult.get("total_count")); }
GqlQuery
example:GqlQuery<?> selectAllGqlQuery = Query.newGqlQueryBuilder( "AGGREGATE COUNT(*) AS total_count, COUNT_UP_TO(100) AS count_upto_100 OVER(SELECT * FROM Task)" ) .setAllowLiteral(true) .build(); AggregationQuery aggregationQuery = Query.newAggregationQueryBuilder() .over(selectAllGqlQuery) .build(); AggregationResults aggregationResults = datastore.runAggregation(aggregationQuery); for (AggregationResult aggregationResult : aggregationResults) { System.out.println(aggregationResult.get("total_count")); System.out.println(aggregationResult.get("count_upto_100")); }
- See Also:
- Datastore queries, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AggregationQuery.Builder
static class
AggregationQuery.Mode
-
Nested classes/interfaces inherited from class com.google.cloud.datastore.Query
Query.ResultType<V>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<Aggregation>
getAggregations()
Returns theAggregation
(s) for this Query.AggregationQuery.Mode
getMode()
Returns theAggregationQuery.Mode
for this query.GqlQuery<?>
getNestedGqlQuery()
Returns the underlyingfor this Query
.StructuredQuery<?>
getNestedStructuredQuery()
Returns the underlyingfor this Query
.-
Methods inherited from class com.google.cloud.datastore.Query
getNamespace, newAggregationQueryBuilder, newEntityQueryBuilder, newGqlQueryBuilder, newGqlQueryBuilder, newKeyQueryBuilder, newProjectionEntityQueryBuilder
-
-
-
-
Method Detail
-
getAggregations
public Set<Aggregation> getAggregations()
Returns theAggregation
(s) for this Query.
-
getNestedStructuredQuery
public StructuredQuery<?> getNestedStructuredQuery()
Returns the underlyingfor this Query
. Returns null if created withGqlQuery
-
getNestedGqlQuery
public GqlQuery<?> getNestedGqlQuery()
Returns the underlyingfor this Query
. Returns null if created withStructuredQuery
-
getMode
public AggregationQuery.Mode getMode()
Returns theAggregationQuery.Mode
for this query.
-
-