Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
morganchen12 wants to merge8 commits intomain
base:main
Choose a base branch
Loading
frommc/pipelines-snippets

Conversation

@morganchen12
Copy link

No description provided.

# [START pipeline_concepts]
pipeline=client.pipeline() \
.collection("cities") \
.where(Field.of("population").greater_than(100000)) \

Choose a reason for hiding this comment

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

suggestion: Python lets you break up large numbers, so you could do100_000 for readability (and consider this for other large numbers in this file)

Copy link
Author

Choose a reason for hiding this comment

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

Done here and throughout


default_app=firebase_admin.initialize_app()
client=firestore.client(default_app,"your-new-enterprise-database")

Choose a reason for hiding this comment

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

We also have anasync 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 forpipeline_initialization_async andbasic_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
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.

daniel-sanche reacted with thumbs up emoji
.execute()
# [END vector_length]
forresinresult:
print(res)

Choose a reason for hiding this comment

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

It would be great if we could have a test file that exercises these functions. Even just running them without verifying outputs would be helpful to make sure no exceptions are thrown, but reading back results would be ideal

It looks like the other samples in this repo aren't tested though, so maybe that would be too much to set up

Copy link
Author

Choose a reason for hiding this comment

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

Will defer to another PR

daniel-sanche reacted with thumbs up emoji
Field.of("rating").average().as_("avg_rating"),
groups=[Field.of("genre")]
) \
.execute()

Choose a reason for hiding this comment

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

If you want to get rid of all the \, IIRC think you could do something like this:

results = (    client.pipeline()    .collection("books")    .aggregate(        Field.of("rating").average().as_("avg_rating"),        groups=[Field.of("genre")]    ).execute())

(But test it first)

Copy link

@daniel-sanchedaniel-sanche left a comment

Choose a reason for hiding this comment

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

Consider adding more imports for Vector, and others that may be missing through the file

But overall LGTM

@morganchen12
Copy link
Author

After adding the snippets for expressions and inputs, I'm getting these errors:

(.venv) morganchen-mac:firebase-admin-python morganchen$ ./lint.sh Running linter on snippets/firestore/firestore_pipelines.py************* Module snippets.firestore.firestore_pipelinessnippets/firestore/firestore_pipelines.py:1770:20: E1101: Module 'firebase_admin.firestore' has no 'SERVER_TIMESTAMP' member (no-member)snippets/firestore/firestore_pipelines.py:2009:41: E1101: Class 'Expression' has no 'array' member (no-member)snippets/firestore/firestore_pipelines.py:2010:16: E1101: Class 'Expression' has no 'array' member (no-member)snippets/firestore/firestore_pipelines.py:2288:12: E1101: Instance of 'Field' has no 'array_get' member (no-member)

For the errors:

  1. I'm not sure why I'm getting this error, it seems to be invoked correctly based on ourdocs
  2. I'm also not sure why I'm getting this error since Array is documentedhere
  3. See 2
  4. Thearray_get method seems to just be missing from the Python SDK.@daniel-sanche this is likely me not reading something somewhere, but just in case it was overlooked

@daniel-sanche
Copy link

  1. One of those isfrom google.cloud import firestore, and the other isfrom firebase_admin import firestore. I'm not super familiar with thefirebase_admin wrapper, but I don't think those are fully equivalent

  2. In the end, I think Array was actually implemented as a stand-alone class:

from google.cloud.firestore_v1.pipeline_expressions import ArrayArray(["bar", Field.of("baz")])

It looks like there's anout-dated docstring. I can fix that.

Let me know if you think it's important to havearray exposed on Expression as well though. I removed it in an effort to keep the API surface manageable, instead of exposing multiple ways of expressing the same thing. But I can add it back if that's more consistent with other languages.

  1. array_get was a late addition, but it should be in the preview branch as of yesterday. Maybe try running again

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@markarndtmarkarndtmarkarndt approved these changes

@wu-huiwu-huiAwaiting requested review from wu-hui

@lahirumarambalahirumarambaAwaiting requested review from lahirumaramba

+1 more reviewer

@daniel-sanchedaniel-sanchedaniel-sanche approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@morganchen12@daniel-sanche@markarndt

[8]ページ先頭

©2009-2025 Movatter.jp