Reference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::Dataset::AggregateQueryResults.
AggregateQueryResults
An AggregateQueryResult object is a representation for a result of an AggregateQuery or a GqlQuery.
Inherits
- Object
Example
require "google/cloud/datastore" datastore = Google::Cloud::Datastore.new query = Google::Cloud::Datastore::Query.new query.kind("Task") .where("done", "=", false) Create an aggregate query aggregate_query = query.aggregate_query .add_count aggregate_query_results = dataset.run_aggregation aggregate_query puts aggregate_query_results.get
Methods
#aggregate_fields
def aggregate_fields() -> Hash{String => Integer, Float}
The result of the aggregation query, returned as a hash of key-value pairs. The key is the alias of the aggregate function, and the value is the result of the aggregation.
The alias of the aggregate function can be:
- an aggregate literal "sum", "avg", or "count"
- a custom aggregate alias
- (Hash{String => Integer, Float})
#get
def get(aggregate_alias = nil) -> Integer, Float, nil
Retrieves the aggregate data.
if the aggregate_alias does not exist.
- aggregate_alias (String) — The alias used to access the aggregate value. For an AggregateQuery with a single aggregate field, this parameter can be omitted.
-
(Integer, Float, nil) — The aggregate value. Returns
nil
require "google/cloud/datastore" datastore = Google::Cloud::Datastore.new query = Google::Cloud::Datastore::Query.new query.kind("Task") .where("done", "=", false) Create an aggregate query aggregate_query = query.aggregate_query .add_count aggregate_query_results = dataset.run_aggregation aggregate_query puts aggregate_query_results.get
Alias an aggregate query
require "google/cloud/datastore" datastore = Google::Cloud::Datastore.new query = Google::Cloud::Datastore::Query.new query.kind("Task") .where("done", "=", false) Create an aggregate query aggregate_query = query.aggregate_query .add_count aggregate_alias: 'total' aggregate_query_results = dataset.run_aggregation aggregate_query puts aggregate_query_results.get('total')
#read_time
def read_time() -> Google::Protobuf::Timestamp
The time when the query was executed.
- (Google::Protobuf::Timestamp)