Skip to content

Commit 4d58a44

Browse files
committed
made subcollection into staticmethod
1 parent d49efd4 commit 4d58a44

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/google-cloud-firestore/google/cloud/firestore_v1/pipeline_source.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ def literals(
172172
"""
173173
return self._create_pipeline(stages.Literals(*documents))
174174

175-
def subcollection(self, path: str) -> SubPipeline:
175+
@staticmethod
176+
def subcollection(path: str) -> SubPipeline:
176177
"""
177178
Initializes a pipeline scoped to a subcollection.
178179
@@ -184,7 +185,7 @@ def subcollection(self, path: str) -> SubPipeline:
184185
185186
Example:
186187
>>> db.pipeline().collection("books").add_fields(
187-
... db.pipeline().subcollection("reviews")
188+
... PipelineSource.subcollection("reviews")
188189
... .aggregate(AggregateFunction.average("rating").as_("avg_rating"))
189190
... .to_scalar_expression().as_("average_rating")
190191
... )

packages/google-cloud-firestore/tests/unit/v1/test_pipeline_source.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from google.cloud.firestore_v1.async_pipeline import AsyncPipeline
1818
from google.cloud.firestore_v1.async_query import AsyncQuery
1919
from google.cloud.firestore_v1.base_document import BaseDocumentReference
20+
from google.cloud.firestore_v1.base_pipeline import SubPipeline
2021
from google.cloud.firestore_v1.pipeline import Pipeline
2122
from google.cloud.firestore_v1.pipeline_source import PipelineSource
2223
from google.cloud.firestore_v1.query import Query
@@ -121,6 +122,16 @@ def test_literals(self):
121122
first_stage = ppl.stages[0]
122123
assert isinstance(first_stage, stages.Literals)
123124

125+
def test_subcollection(self):
126+
expected_path = "/a/b/c"
127+
ppl = PipelineSource.subcollection(expected_path)
128+
assert isinstance(ppl, SubPipeline)
129+
assert len(ppl.stages) == 1
130+
first_stage = ppl.stages[0]
131+
assert isinstance(first_stage, stages.Subcollection)
132+
assert first_stage.path == expected_path
133+
134+
124135

125136
class TestPipelineSourceWithAsyncClient(TestPipelineSource):
126137
"""

0 commit comments

Comments
 (0)