Skip to content
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

feat(firestore): Add Query#limit_to_last #7575

Merged
merged 5 commits into from
Aug 31, 2020

Conversation

quartzmo
Copy link
Member

@quartzmo quartzmo commented Aug 14, 2020

closes: #7572
closes: #7594

/cc @schmidt-sebastian

@quartzmo quartzmo requested a review from a team as a code owner August 14, 2020 19:03
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 14, 2020
@quartzmo quartzmo self-assigned this Aug 14, 2020
@quartzmo quartzmo added the api: firestore Issues related to the Firestore API. label Aug 14, 2020
google-cloud-firestore/lib/google/cloud/firestore/query.rb Outdated Show resolved Hide resolved
new_start_at = new_query.end_at.dup
new_end_at = new_query.start_at.dup
new_query.start_at = new_start_at
new_query.end_at = new_end_at

Choose a reason for hiding this comment

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

You also need to switch the "before" direction.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks!

google-cloud-firestore/lib/google/cloud/firestore/query.rb Outdated Show resolved Hide resolved

_(snps.count).must_equal 2
_(snps[0].count).must_equal 2
_(snps[0].docs.map(&:document_id)).must_equal ["int 3", "int 2"]

Choose a reason for hiding this comment

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

Can we make sure this test verifies that the order is "int 2", "int 3"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that, will do. I'll also change line 65 below to ["int 3", "int 4"]

Copy link
Member Author

Choose a reason for hiding this comment

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

@schmidt-sebastian Can you see the mistake I made in the implementation that causes this result? This is an integration test that currently passes.

Choose a reason for hiding this comment

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

I can take a look at the code if you need me to, but I haven't yet. My strong suspicion is that you are using the flipped query but not re-flipping the results (you always need to reverse the results if you are flipping the orderBy constraints on the user's behalf). The way I do this is Node and Java is that I use the pre-flipped query to process the local results.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds likely, thank you.

Copy link
Member Author

@quartzmo quartzmo Aug 20, 2020

Choose a reason for hiding this comment

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

@schmidt-sebastian I updated Inventory to reverse the results for limit_to_last queries. I'm sorry I missed that the first time. Please take a look at the additional assertions for changes ordering to verify that it is correct. (I'm not sure if changes ordering should reflect query orderBy.)

Choose a reason for hiding this comment

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

This looks correct now. It is slightly different than what I have implemented since the Watch client in Ruby uses the reversed query Proto for its ordering, rather than the user-specified Query order. In the end this does not matter though, since we only need to match the user's order by clause. With the reversal this is now working as intended.

Copy link
Member Author

Choose a reason for hiding this comment

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

@schmidt-sebastian Thank you for your help on this PR! I'm going to add samples for this feature (as in GoogleCloudPlatform/python-docs-samples#4196), then ask @dazuma to review for Ruby concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Added sample in 13c2253

@quartzmo
Copy link
Member Author

Rebased on latest master to get samples directory.

@quartzmo quartzmo force-pushed the firestore-limit-to-last branch 2 times, most recently from 9dd8dd9 to 13c2253 Compare August 27, 2020 20:40
@quartzmo quartzmo merged commit 7a834b0 into googleapis:master Aug 31, 2020
@quartzmo quartzmo deleted the firestore-limit-to-last branch August 31, 2020 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the Firestore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

firestore: Add samples for limit_to_last Add support for Firestore Query#limit_to_last
3 participants