3939 from google .cloud .firestore_v1 .query_profile import ExplainMetrics
4040 from google .cloud .firestore_v1 .query_profile import ExplainOptions
4141
42+ import datetime
43+
4244
4345class AggregationQuery (BaseAggregationQuery ):
4446 """Represents an aggregation query to the Firestore API."""
@@ -56,6 +58,7 @@ def get(
5658 timeout : float | None = None ,
5759 * ,
5860 explain_options : Optional [ExplainOptions ] = None ,
61+ read_time : Optional [datetime .datetime ] = None ,
5962 ) -> QueryResultsList [AggregationResult ]:
6063 """Runs the aggregation query.
6164
@@ -78,6 +81,10 @@ def get(
7881 (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
7982 Options to enable query profiling for this query. When set,
8083 explain_metrics will be available on the returned generator.
84+ read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
85+ time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
86+ is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
87+ timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.
8188
8289 Returns:
8390 QueryResultsList[AggregationResult]: The aggregation query results.
@@ -90,6 +97,7 @@ def get(
9097 retry = retry ,
9198 timeout = timeout ,
9299 explain_options = explain_options ,
100+ read_time = read_time ,
93101 )
94102 result_list = list (result )
95103
@@ -100,13 +108,16 @@ def get(
100108
101109 return QueryResultsList (result_list , explain_options , explain_metrics )
102110
103- def _get_stream_iterator (self , transaction , retry , timeout , explain_options = None ):
111+ def _get_stream_iterator (
112+ self , transaction , retry , timeout , explain_options = None , read_time = None
113+ ):
104114 """Helper method for :meth:`stream`."""
105115 request , kwargs = self ._prep_stream (
106116 transaction ,
107117 retry ,
108118 timeout ,
109119 explain_options ,
120+ read_time ,
110121 )
111122
112123 return self ._client ._firestore_api .run_aggregation_query (
@@ -132,6 +143,7 @@ def _make_stream(
132143 retry : Union [retries .Retry , None , object ] = gapic_v1 .method .DEFAULT ,
133144 timeout : Optional [float ] = None ,
134145 explain_options : Optional [ExplainOptions ] = None ,
146+ read_time : Optional [datetime .datetime ] = None ,
135147 ) -> Generator [List [AggregationResult ], Any , Optional [ExplainMetrics ]]:
136148 """Internal method for stream(). Runs the aggregation query.
137149
@@ -155,6 +167,10 @@ def _make_stream(
155167 (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
156168 Options to enable query profiling for this query. When set,
157169 explain_metrics will be available on the returned generator.
170+ read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
171+ time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
172+ is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
173+ timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.
158174
159175 Yields:
160176 List[AggregationResult]:
@@ -172,6 +188,7 @@ def _make_stream(
172188 retry ,
173189 timeout ,
174190 explain_options ,
191+ read_time ,
175192 )
176193 while True :
177194 try :
@@ -182,6 +199,8 @@ def _make_stream(
182199 transaction ,
183200 retry ,
184201 timeout ,
202+ explain_options ,
203+ read_time ,
185204 )
186205 continue
187206 else :
@@ -206,6 +225,7 @@ def stream(
206225 timeout : Optional [float ] = None ,
207226 * ,
208227 explain_options : Optional [ExplainOptions ] = None ,
228+ read_time : Optional [datetime .datetime ] = None ,
209229 ) -> StreamGenerator [List [AggregationResult ]]:
210230 """Runs the aggregation query.
211231
@@ -229,6 +249,10 @@ def stream(
229249 (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
230250 Options to enable query profiling for this query. When set,
231251 explain_metrics will be available on the returned generator.
252+ read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
253+ time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
254+ is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
255+ timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.
232256
233257 Returns:
234258 `StreamGenerator[List[AggregationResult]]`:
@@ -239,5 +263,6 @@ def stream(
239263 retry = retry ,
240264 timeout = timeout ,
241265 explain_options = explain_options ,
266+ read_time = read_time ,
242267 )
243268 return StreamGenerator (inner_generator , explain_options )
0 commit comments