Aggregation¶
Classes for representing aggregation queries for the Google Cloud Firestore API.
A AggregationQuery
can be created directly from
a Collection
and that can be
a more common way to create an aggregation query than direct usage of the constructor.
- class google.cloud.firestore_v1.aggregation.AggregationQuery(nested_query)[source]¶
Bases:
google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery
Represents an aggregation query to the Firestore API.
- get(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) List[AggregationResult] [source]¶
Runs the aggregation query.
This sends a
RunAggregationQuery
RPC and returns a list of aggregation results in the stream ofRunAggregationQueryResponse
messages.- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in. If atransaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Returns
The aggregation query results
- Return type
- stream(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) Union[Generator[List[AggregationResult], Any, None]] [source]¶
Runs the aggregation query.
This sends a
RunAggregationQuery
RPC and then returns an iterator which consumes each document returned in the stream ofRunAggregationQueryResponse
messages.If a
transaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in.retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Yields
AggregationResult
– The result of aggregations of this query
Classes for representing aggregation queries for the Google Cloud Firestore API.
A AggregationQuery
can be created directly from
a Collection
and that can be
a more common way to create an aggregation query than direct usage of the constructor.
- class google.cloud.firestore_v1.base_aggregation.AggregationResult(alias: str, value: int, read_time=None)[source]¶
Bases:
object
A class representing result from Aggregation Query :type alias: str :param alias: The alias for the aggregation. :type value: int :param value: The resulting value from the aggregation. :type read_time: :param value: The resulting read_time
- class google.cloud.firestore_v1.base_aggregation.AvgAggregation(field_ref: str | FieldPath, alias: str | None = None)[source]¶
Bases:
google.cloud.firestore_v1.base_aggregation.BaseAggregation
- class google.cloud.firestore_v1.base_aggregation.BaseAggregation(alias: str | None = None)[source]¶
Bases:
abc.ABC
- class google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery(nested_query, alias: str | None = None)[source]¶
Bases:
abc.ABC
Represents an aggregation query to the Firestore API.
- add_aggregation(aggregation: google.cloud.firestore_v1.base_aggregation.BaseAggregation) None [source]¶
Adds an aggregation operation to the nested query
- Parameters
aggregation (
google.cloud.firestore_v1.aggregation.BaseAggregation
) – An aggregation operation, e.g. a CountAggregation
- add_aggregations(aggregations: List[google.cloud.firestore_v1.base_aggregation.BaseAggregation]) None [source]¶
Adds a list of aggregations to the nested query
- Parameters
aggregations (list) – a list of aggregation operations
- avg(field_ref: str | FieldPath, alias: str | None = None)[source]¶
Adds an avg over the nested query
- abstract get(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) List[AggregationResult] | Coroutine[Any, Any, List[AggregationResult]] [source]¶
Runs the aggregation query.
This sends a
RunAggregationQuery
RPC and returns a list of aggregation results in the stream ofRunAggregationQueryResponse
messages.- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in. If atransaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Returns
The aggregation query results
- Return type
- abstract stream(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) Generator[List[AggregationResult], Any, None] | AsyncGenerator[List[AggregationResult], None] [source]¶
Runs the aggregation query.
This sends a``RunAggregationQuery`` RPC and returns an iterator in the stream of
RunAggregationQueryResponse
messages.- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in. If atransaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Returns
The aggregation query results
- Return type
- class google.cloud.firestore_v1.base_aggregation.CountAggregation(alias: str | None = None)[source]¶
Bases:
google.cloud.firestore_v1.base_aggregation.BaseAggregation
- class google.cloud.firestore_v1.base_aggregation.SumAggregation(field_ref: str | FieldPath, alias: str | None = None)[source]¶
Bases:
google.cloud.firestore_v1.base_aggregation.BaseAggregation
Classes for representing Async aggregation queries for the Google Cloud Firestore API.
A AsyncAggregationQuery
can be created directly from
a AsyncCollection
and that can be
a more common way to create an aggregation query than direct usage of the constructor.
- class google.cloud.firestore_v1.async_aggregation.AsyncAggregationQuery(nested_query)[source]¶
Bases:
google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery
Represents an aggregation query to the Firestore API.
- async get(transaction=None, retry: Union[retries.AsyncRetry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) List[AggregationResult] [source]¶
Runs the aggregation query.
This sends a
RunAggregationQuery
RPC and returns a list of aggregation results in the stream ofRunAggregationQueryResponse
messages.- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in. If atransaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Returns
The aggregation query results
- Return type
- async stream(transaction=None, retry: Union[retries.AsyncRetry, None, gapic_v1.method._MethodDefault] = _MethodDefault._DEFAULT_VALUE, timeout: float | None = None) Union[AsyncGenerator[List[AggregationResult], None]] [source]¶
Runs the aggregation query.
This sends a
RunAggregationQuery
RPC and then returns an iterator which consumes each document returned in the stream ofRunAggregationQueryResponse
messages.If a
transaction
is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).- Parameters
transaction – (Optional[
Transaction
]): An existing transaction that this query will run in.retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
timeout (float) – The timeout for this request. Defaults to a system-specified value.
- Yields
AggregationResult
– The result of aggregations of this query