KEMBAR78
feat: Query.count() implementation, part 1 by dconeybe · Pull Request #1026 · googleapis/java-firestore · GitHub
Skip to content

Conversation

@dconeybe
Copy link
Contributor

Initial implementation of server-side query result set counting.

This initial implementation is still missing some work, which will be done in follow-up PRs:

  • transaction support (i.e. Transaction.getCount())
  • tracing support (i.e. Tracing.getTracer())

@dconeybe dconeybe added the api: firestore Issues related to the googleapis/java-firestore API. label Aug 26, 2022
@dconeybe dconeybe self-assigned this Aug 26, 2022
@dconeybe dconeybe changed the title Query.count() added feat: Query.count() added Aug 26, 2022
@conventional-commit-lint-gcf
Copy link

conventional-commit-lint-gcf bot commented Aug 26, 2022

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@dconeybe dconeybe force-pushed the dconeybe/CountDraft1 branch from 0dfda07 to 7467804 Compare August 26, 2022 17:01
@dconeybe dconeybe changed the title feat: Query.count() added feat: Query.count() implementation, part 1 Aug 26, 2022
@dconeybe dconeybe force-pushed the dconeybe/CountDraft1 branch from 7467804 to 1be2496 Compare August 26, 2022 17:04
@dconeybe dconeybe requested a review from wu-hui August 26, 2022 17:08
throws Exception {
CollectionReference collection = createCollectionWithDocuments(20);
ApiFuture<AggregateQuerySnapshot> task = collection.count().get();
collection.getFirestore().close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, will this be flaky?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

close() appears to peform a "graceful" shutdown, in which in-flight operations are allowed to run to completion. That being the case, this shouldn't be flaky.

Copy link
Contributor

Choose a reason for hiding this comment

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

So if for whatever reason the backend does not respond, close() will hang forever?

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 believe so, yes. The main thing I want to test is that nothing "bad" happens, like silly exceptions that simply didn't take this code path into account. I can confirm if you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I would like to see it for my curiosity now. Not a blocker for this PR though.

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 looked into whether or not close() will hang forever if the server takes too long to respond, and, it appears that no, it will not hang. That being said, it's difficult to tell from stepping through the gory details of grpc's shutdown logic.

* Blocks the calling thread until the given future completes. Note that this method does not
* check the success or failure of the future; it returns regardless of its success or failure.
*/
private static void await(ApiFuture<?> future) throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use future.get()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

future.get() will throw the exception if the task fails, which isn't the desired behavior for the singular use of this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this do:

try {future.get()} finally {assertTrue(future.done());}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would still throw the exception thrown by get(). The caller of await() just wants to make sure that the future completes, but doesn't care about its success or failure.

@wu-hui wu-hui removed their assignment Aug 29, 2022
@dconeybe dconeybe marked this pull request as ready for review August 29, 2022 15:00
@dconeybe dconeybe requested a review from a team as a code owner August 29, 2022 15:00
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!

throws Exception {
CollectionReference collection = createCollectionWithDocuments(20);
ApiFuture<AggregateQuerySnapshot> task = collection.count().get();
collection.getFirestore().close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I would like to see it for my curiosity now. Not a blocker for this PR though.

@dconeybe dconeybe merged commit 80189c1 into count Aug 31, 2022
@dconeybe dconeybe deleted the dconeybe/CountDraft1 branch August 31, 2022 14:36
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 googleapis/java-firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants