Skip to content
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b17f8f1
add initial pipelines snippet file
morganchen12 Nov 3, 2025
71c481f
add pipeline snippets for python
morganchen12 Nov 4, 2025
cf8b63e
address feedback except formatting
morganchen12 Nov 6, 2025
45302f8
run format
morganchen12 Nov 6, 2025
9df189b
remove confusing async bit
morganchen12 Nov 7, 2025
f84c39d
Add expression and input snippets, with errors
morganchen12 Nov 11, 2025
b17342b
add query explain snippet and fix lint errors
morganchen12 Nov 11, 2025
79e3d2b
fix explainoptions snippet
morganchen12 Nov 12, 2025
addbcbf
add type and constant functions
morganchen12 Jan 14, 2026
84d9c85
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Apr 15, 2026
bff59b7
add snippets except forceindex (not supported)
morganchen12 Apr 15, 2026
c2db983
Add snippets for inserting data used by other snippets
morganchen12 Apr 17, 2026
eb62188
add search and geo snippets
morganchen12 Apr 20, 2026
3ab8ef2
code review feedback
morganchen12 May 15, 2026
7851ad5
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jun 26, 2026
8ca4f37
feat(fcm): Enable `fid` and deprecate `token` for Send API (#951)
yvonnep165 Jun 29, 2026
a3f6df8
fix(deps): Added universe_domain override to MockGoogleComputeEngineC…
lahirumaramba Jun 29, 2026
ef49e31
chore(deps): update pyjwt requirement from >=2.10.1 to >=2.12.1 (#948)
dependabot[bot] Jun 29, 2026
f3e8ed8
chore(deps): update google-cloud-firestore requirement (#947)
dependabot[bot] Jun 29, 2026
486597b
chore(deps): update pytest requirement from >=8.2.2 to >=8.4.2 (#946)
dependabot[bot] Jun 29, 2026
43e5543
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jun 29, 2026
4a6ce82
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jul 31, 2026
c4ba7c0
add snippets for joins and explain (#973)
morganchen12 Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 18 additions & 31 deletions snippets/firestore/firestore_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# from google.cloud.firestore import Query
# from google.cloud.firestore_v1.pipeline import Pipeline
# from google.cloud.firestore_v1.pipeline_source import PipelineSource
# from google.cloud.firestore_v1.pipeline_expressions import (
# AggregateFunction,
# Constant,
# Expression,
# Field,
# Count,
# )
# from google.cloud.firestore_v1.pipeline_expressions import (
# And,
# Conditional,
# Or,
# Not,
# Xor,
# )
# from google.cloud.firestore_v1.pipeline_stages import (
# Aggregate,
# FindNearestOptions,
# SampleOptions,
# UnnestOptions,
# )
# from google.cloud.firestore_v1.base_vector_query import DistanceMeasure
# from google.cloud.firestore_v1.vector import Vector
# from google.cloud.firestore_v1.client import Client

import firebase_admin
from firebase_admin import firestore

Expand All @@ -47,6 +20,19 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have an async version of everything.

Often, we re-write the samples for both sync and async, and show both options in the language selection pickers. I'm not sure how you want to handle that here.

Maybe a couple samples for pipeline_initialization_async and basic_read_async is enough to show it exists, since the API is almost identical. Or maybe samples for async aren't needed for preview

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to get to the async versions after Java and if I don't get to it by launch day it'll just be a follow-on.


# pylint: disable=invalid-name

def query_explain():
# [START query_explain]
from google.cloud.firestore import Query, FieldFilter, ExplainOptions

results = client.collection("cities") \
.where(filter=FieldFilter("capital", "==", True)) \
.execute(explain_options=ExplainOptions(analyze=False))
metrics = results.explain_metrics()
summary = metrics.plan_summary()
Comment thread
morganchen12 marked this conversation as resolved.
Outdated
# [END query_explain]


def pipeline_concepts():
# [START pipeline_concepts]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we'd want all region tags to start with the product prefix, so firestore_pipeline_concepts. But are other samples already written with these tags?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I omitted firestore_ where the filepath contained firestore somewhere. The snippets tool and the includecode tool both reference the filepath when importing statements so it'll still be findable as a Firestore snippet.

from google.cloud.firestore_v1.pipeline_expressions import Field
Expand Down Expand Up @@ -1764,7 +1750,7 @@ def vector_length_function():
def stages_expressions_example():
# [START stages_expressions_example]
from google.cloud.firestore_v1.pipeline_expressions import Field, Constant
from firebase_admin import firestore
from google.cloud import firestore

trailing_30_days = (
Constant.of(firestore.SERVER_TIMESTAMP)
Expand Down Expand Up @@ -1995,9 +1981,10 @@ def unnest_empty_array_example():
def unnest_preserve_empty_array_example():
# [START unnest_preserve_empty_array]
from google.cloud.firestore_v1.pipeline_expressions import (
Field,
Array,
Conditional,
Expression,
Field,
)
from google.cloud.firestore_v1.pipeline_stages import UnnestOptions

Expand All @@ -2006,8 +1993,8 @@ def unnest_preserve_empty_array_example():
.collection("users")
.unnest(
Conditional(
Field.of("scores").equal(Expression.array([])),
Expression.array([Field.of("scores")]),
Field.of("scores").equal(Array([])),
Array([Field.of("scores")]),
Field.of("scores"),
).as_("userScore"),
options=UnnestOptions(index_field="attempt"),
Expand Down
Loading