Skip to content

Conversation

@morganchen12
Copy link

No description provided.

# [START basic_read]
pipeline = client.pipeline().collection("users")
for result in pipeline.execute():
print(result.id + " => " + result.data)

Choose a reason for hiding this comment

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

f-strings are usually preferred to concatenation: print(f"{result.id} => {result.data}")

Copy link
Author

Choose a reason for hiding this comment

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

Done

# [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 do 100_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

# [START basic_read]
pipeline = client.pipeline().collection("users")
for result in pipeline.execute():
print(result.id + " => " + result.data)

Choose a reason for hiding this comment

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

It looks like result.data is a method and not a property, so I think you need to call it: result.data()

Copy link
Author

Choose a reason for hiding this comment

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

Done

# [START field_or_constant]
pipeline = client.pipeline() \
.collection("cities") \
.where(Field.of("name").equal(Constant("Toronto")))

Choose a reason for hiding this comment

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

you can also do Constant.of("Toronto"), to match Field.of. I'm not sure which is preferred

Copy link
Author

Choose a reason for hiding this comment

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

Done for consistency


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 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
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.

.execute()
# [END vector_length]
for res in result:
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

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-sanche daniel-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

# [START cosine_distance]
from google.cloud.firestore_v1.pipeline_expressions import Field

sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])

Choose a reason for hiding this comment

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

I'd recommend adding the import for Vector in the sample as well

(maybe you should remove most imports from the top of the file, so it will be clear where sample imports are needed?)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants