-
Notifications
You must be signed in to change notification settings - Fork 343
Add pipeline snippets for Firestore #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
b17f8f1
71c481f
cf8b63e
45302f8
9df189b
f84c39d
b17342b
79e3d2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -47,6 +20,19 @@ | |
|
|
||
|
|
||
| # 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() | ||
morganchen12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # [END query_explain] | ||
|
|
||
|
|
||
| def pipeline_concepts(): | ||
| # [START pipeline_concepts] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I omitted |
||
| from google.cloud.firestore_v1.pipeline_expressions import Field | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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"), | ||
|
|
||
There was a problem hiding this comment.
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_asyncandbasic_read_asyncis enough to show it exists, since the API is almost identical. Or maybe samples for async aren't needed for previewThere was a problem hiding this comment.
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.