public class AggregationQuery extends Query<AggregationResults>
AggregationResults
, It
can be constructed by providing a nested query (StructuredQuery
or GqlQuery
) to
run the aggregations on and a set of Aggregation
.
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"));
}
Modifier and Type | Class and Description |
---|---|
static class |
AggregationQuery.Builder |
static class |
AggregationQuery.Mode |
Query.ResultType<V>
Modifier and Type | Method and Description |
---|---|
Set<Aggregation> |
getAggregations()
Returns the
Aggregation (s) for this Query. |
AggregationQuery.Mode |
getMode()
Returns the
AggregationQuery.Mode for this query. |
GqlQuery<?> |
getNestedGqlQuery()
Returns the underlying
for this Query . |
StructuredQuery<?> |
getNestedStructuredQuery()
Returns the underlying
for this Query . |
getNamespace, newAggregationQueryBuilder, newEntityQueryBuilder, newGqlQueryBuilder, newGqlQueryBuilder, newKeyQueryBuilder, newProjectionEntityQueryBuilder
public Set<Aggregation> getAggregations()
Aggregation
(s) for this Query.public StructuredQuery<?> getNestedStructuredQuery()
for this Query
. Returns null if created with
GqlQuery
public GqlQuery<?> getNestedGqlQuery()
for this Query
. Returns null if created with StructuredQuery
public AggregationQuery.Mode getMode()
AggregationQuery.Mode
for this query.Copyright © 2023 Google LLC. All rights reserved.