Class Aggregation (2.13.1)

Aggregation(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Defines an aggregation that produces a single result.

This message has oneof_ fields (mutually exclusive fields). For each oneof, at most one member field can be set at the same time. Setting any member of the oneof automatically clears all other members.

.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields

Attributes

NameDescription
count google.cloud.firestore_v1.types.StructuredAggregationQuery.Aggregation.Count
Count aggregator. This field is a member of oneof_ operator.
sum google.cloud.firestore_v1.types.StructuredAggregationQuery.Aggregation.Sum
Sum aggregator. This field is a member of oneof_ operator.
avg google.cloud.firestore_v1.types.StructuredAggregationQuery.Aggregation.Avg
Average aggregator. This field is a member of oneof_ operator.
alias str
Optional. Optional name of the field to store the result of the aggregation into. If not provided, Firestore will pick a default name following the format field_. For example: :: AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2), COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) OVER ( ... ); becomes: :: AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2) AS field_1, COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) AS field_2 OVER ( ... ); Requires: - Must be unique across all aggregation aliases. - Conform to [document field name][google.firestore.v1.Document.fields] limitations.

Classes

Avg

Avg(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Average of the values of the requested field.

  • Only numeric values will be aggregated. All non-numeric values including NULL are skipped.

  • If the aggregated values contain NaN, returns NaN. Infinity math follows IEEE-754 standards.

  • If the aggregated value set is empty, returns NULL.

  • Always returns the result as a double.

Count

Count(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Count of documents that match the query.

The COUNT(*) aggregation function operates on the entire document so it does not require a field reference.

Sum

Sum(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Sum of the values of the requested field.

  • Only numeric values will be aggregated. All non-numeric values including NULL are skipped.

  • If the aggregated values contain NaN, returns NaN. 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.