1313# limitations under the License.
1414
1515from __future__ import annotations
16- from typing import AsyncIterable , TYPE_CHECKING
16+ from typing import TYPE_CHECKING
1717from google .cloud .firestore_v1 import pipeline_stages as stages
1818from google .cloud .firestore_v1 .base_pipeline import _BasePipeline
19+ from google .cloud .firestore_v1 .pipeline_result import AsyncPipelineStream
20+ from google .cloud .firestore_v1 .pipeline_result import PipelineSnapshot
21+ from google .cloud .firestore_v1 .pipeline_result import PipelineResult
1922
2023if TYPE_CHECKING : # pragma: NO COVER
24+ import datetime
2125 from google .cloud .firestore_v1 .async_client import AsyncClient
22- from google .cloud .firestore_v1 .pipeline_result import PipelineResult
2326 from google .cloud .firestore_v1 .async_transaction import AsyncTransaction
27+ from google .cloud .firestore_v1 .pipeline_expressions import Constant
28+ from google .cloud .firestore_v1 .types .document import Value
29+ from google .cloud .firestore_v1 .query_profile import PipelineExplainOptions
2430
2531
2632class AsyncPipeline (_BasePipeline ):
@@ -40,7 +46,7 @@ class AsyncPipeline(_BasePipeline):
4046 ... .collection("books")
4147 ... .where(Field.of("published").gt(1980))
4248 ... .select("title", "author")
43- ... async for result in pipeline.execute ():
49+ ... async for result in pipeline.stream ():
4450 ... print(result)
4551
4652 Use `client.pipeline()` to create instances of this class.
@@ -58,39 +64,68 @@ def __init__(self, client: AsyncClient, *stages: stages.Stage):
5864
5965 async def execute (
6066 self ,
67+ * ,
6168 transaction : "AsyncTransaction" | None = None ,
62- ) -> list [PipelineResult ]:
69+ read_time : datetime .datetime | None = None ,
70+ explain_options : PipelineExplainOptions | None = None ,
71+ index_mode : str | None = None ,
72+ additional_options : dict [str , Value | Constant ] = {},
73+ ) -> PipelineSnapshot [PipelineResult ]:
6374 """
6475 Executes this pipeline and returns results as a list
6576
6677 Args:
67- transaction
68- (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
78+ transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
6979 An existing transaction that this query will run in.
7080 If a ``transaction`` is used and it already has write operations
7181 added, this method cannot be used (i.e. read-after-write is not
7282 allowed).
83+ read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
84+ time. This must be a microsecond precision timestamp within the past one hour, or
85+ if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
86+ within the past 7 days. For the most accurate results, use UTC timezone.
87+ explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
88+ Options to enable query profiling for this query. When set,
89+ explain_metrics will be available on the returned list.
90+ index_mode (Optional[str]): Configures the pipeline to require a certain type of indexes to be present.
91+ Firestore will reject the request if there is not appropiate indexes to serve the query.
92+ additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
93+ These options will take precedence over method argument if there is a conflict (e.g. explain_options, index_mode)
7394 """
74- return [result async for result in self .stream (transaction = transaction )]
95+ kwargs = {k : v for k , v in locals ().items () if k != "self" }
96+ stream = AsyncPipelineStream (PipelineResult , self , ** kwargs )
97+ results = [result async for result in stream ]
98+ return PipelineSnapshot (results , stream )
7599
76- async def stream (
100+ def stream (
77101 self ,
102+ * ,
103+ read_time : datetime .datetime | None = None ,
78104 transaction : "AsyncTransaction" | None = None ,
79- ) -> AsyncIterable [PipelineResult ]:
105+ explain_options : PipelineExplainOptions | None = None ,
106+ index_mode : str | None = None ,
107+ additional_options : dict [str , Value | Constant ] = {},
108+ ) -> AsyncPipelineStream [PipelineResult ]:
80109 """
81- Process this pipeline as a stream, providing results through an Iterable
110+ Process this pipeline as a stream, providing results through an AsyncIterable
82111
83112 Args:
84- transaction
85- (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
113+ transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
86114 An existing transaction that this query will run in.
87115 If a ``transaction`` is used and it already has write operations
88116 added, this method cannot be used (i.e. read-after-write is not
89117 allowed).
118+ read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
119+ time. This must be a microsecond precision timestamp within the past one hour, or
120+ if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
121+ within the past 7 days. For the most accurate results, use UTC timezone.
122+ explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
123+ Options to enable query profiling for this query. When set,
124+ explain_metrics will be available on the returned generator.
125+ index_mode (Optional[str]): Configures the pipeline to require a certain type of indexes to be present.
126+ Firestore will reject the request if there is not appropiate indexes to serve the query.
127+ additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
128+ These options will take precedence over method argument if there is a conflict (e.g. explain_options, index_mode)
90129 """
91- request = self ._prep_execute_request (transaction )
92- async for response in await self ._client ._firestore_api .execute_pipeline (
93- request
94- ):
95- for result in self ._execute_response_helper (response ):
96- yield result
130+ kwargs = {k : v for k , v in locals ().items () if k != "self" }
131+ return AsyncPipelineStream (PipelineResult , self , ** kwargs )
0 commit comments