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: add Query.limitToLast() #151

Merged

Conversation

schmidt-sebastian
Copy link
Contributor

Adds limitToLast() support to Java Firestore.

Port of https://github.com/googleapis/nodejs-firestore/pull/954/files

Also changes the ITWatchTests to use Lists instead of Sets, which allows us to verify ordering

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 25, 2020
@schmidt-sebastian schmidt-sebastian changed the title Mrschmidt/limittolast feat: add Query.limitToLast() Mar 25, 2020
@codecov
Copy link

codecov bot commented Mar 25, 2020

Codecov Report

Merging #151 into master will increase coverage by 0.07%.
The diff coverage is 85.71%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #151      +/-   ##
============================================
+ Coverage     71.62%   71.69%   +0.07%     
- Complexity      969      975       +6     
============================================
  Files            62       62              
  Lines          5222     5257      +35     
  Branches        579      588       +9     
============================================
+ Hits           3740     3769      +29     
  Misses         1302     1302              
- Partials        180      186       +6     
Impacted Files Coverage Δ Complexity Δ
...rc/main/java/com/google/cloud/firestore/Query.java 90.99% <85.71%> (-0.74%) 100.00 <4.00> (+6.00) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ccdf21...0a5deea. Read the comment docs.

/**
* Creates and returns a new Query that only returns the last matching documents.
*
* <p>You must specify at least one orderBy clause for limitToLast queries, otherwise an exception
Copy link
Contributor

Choose a reason for hiding this comment

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

. Otherwise
which exception type specifically? This might use a throws clause for that info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mentioned this is an IllegalStateException.

* <p>Results for limitToLast queries cannot be streamed via the {@link
* #stream(ApiStreamObserver)} API.
*
* @param limit The maximum number of items to return.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the (no caps) and no period at end since this is not a complete sentence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left it as is for now to be consistent with the rest of the code. I will send a PR once this is merged to clean this up everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Google Java practices explicitly rule out consistency with existing code as a justification for violating style guidelines in newly added code:

https://engdoc.corp.google.com/eng/doc/devguide/java/style/index.md?cl=head#s8.5.2-newly-added-code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

* #stream(ApiStreamObserver)} API.
*
* @param limit The maximum number of items to return.
* @return The created Query.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

listenerAssertions.addedIdsIsAnyOf(emptySet(), newHashSet("doc"));
listenerAssertions.modifiedIdsIsAnyOf(emptySet());
listenerAssertions.removedIdsIsAnyOf(emptySet());
listenerAssertions.addedIdsIsAnyOf(emptyList(), singletonList("doc"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is surprising. Shouldn't it be one or the other deterministically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I fixed this instance, I think there are a couple other tests that could use tighter assertions. @BenWhitehead did go out of his way to make sure that these tests are not flaky, so I suspect some of these are intended.

Copy link
Collaborator

Choose a reason for hiding this comment

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

After thousands of iterations of these tests there is a fairly broad amount of wiggle room from the backend around event delivery and potential collection. There are a number of internal SLOs that are monitored by the backend, but no SLA related to the events being delivered in a certain amount of time. Due to these observations, I added the any-of checks in several locations to reduce the flakiness of these tests. If there were publicly available SLAs for the event listener we could tighten up the tests bounds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on @BenWhitehead comment, I reverted this change.

Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

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

LGTM, FWIW..

Copy link
Collaborator

@BenWhitehead BenWhitehead left a comment

Choose a reason for hiding this comment

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

A couple nits and one recommendation.

Let me know your decision then I can approve and merge.

/**
* Creates and returns a new Query that only returns the last matching documents.
*
* <p>You must specify at least one orderBy clause for limitToLast queries, otherwise an {@link
Copy link
Contributor

Choose a reason for hiding this comment

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

, otherwise --> . Otherwise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* Creates and returns a new Query that only returns the last matching documents.
*
* <p>You must specify at least one orderBy clause for limitToLast queries, otherwise an {@link
* java.lang.IllegalStateException} will be thrown during execution.
Copy link
Contributor

Choose a reason for hiding this comment

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

will be --> is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* <p>Results for limitToLast queries cannot be streamed via the {@link
* #stream(ApiStreamObserver)} API.
*
* @param limit The maximum number of items to return.
Copy link
Contributor

Choose a reason for hiding this comment

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

Google Java practices explicitly rule out consistency with existing code as a justification for violating style guidelines in newly added code:

https://engdoc.corp.google.com/eng/doc/devguide/java/style/index.md?cl=head#s8.5.2-newly-added-code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants