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

Firestore: add support for CollectionGroup queries. #7758

Merged
merged 18 commits into from
Apr 30, 2019

Conversation

crwilcox
Copy link
Contributor

@crwilcox crwilcox commented Apr 19, 2019

CollectionGroup queries add support for queries to Firestore that query documents by collection ID rather than by collection path.

Java: googleapis/google-cloud-java#4652
Node: googleapis/nodejs-firestore#578

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Apr 19, 2019
@crwilcox crwilcox added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 19, 2019
Copy link

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

This looks sane to me, but please have someone from the Python team look at this as well. Thanks so much!



def _collection_group_query_response_to_snapshot(response_pb, collection):
"""Parse a query response protobuf to a document snapshot.

Choose a reason for hiding this comment

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

I am a little surprised that this is a different method from _query_response_to_snapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was related to expectations built into this method. @tseaver made this to address that. It is possible we can combine them by refactoring that code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@schmidt-sebastian The implementation of _query_response_to_snapshot mandates (via _helpers.get_doc_id) that the result document is a direct child of the query's parent collection. I'm unsure whether this restriction is "important", or just an artifact of prior development iterations. If it is an artifact, then we could just use the new implementation in _collection_group_query_response_to_snapshot for all queries.

is not set, the snapshot will be :data:`None`.
"""
if not response_pb.HasField("document"):
return None

Choose a reason for hiding this comment

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

Does Python not return empty DocumentSnapshots for non-existing documents? In either case, this is a query and this condition should never trigger (fingers crossed).

Copy link
Contributor

Choose a reason for hiding this comment

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

@schmidt-sebastian DocumentReference.get does return an empty snapshot for a non-existent document. For the query case, the back-end can return a response without a document when reporting partial results: see #6924 and PR #7206 for the history.

Copy link

@schmidt-sebastian schmidt-sebastian Apr 23, 2019

Choose a reason for hiding this comment

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

firestore/tests/system.py Outdated Show resolved Hide resolved
@danoscarmike
Copy link
Contributor

@tseaver can you give this one your blessing too? Thanks!

@tseaver
Copy link
Contributor

tseaver commented Apr 22, 2019

@danoscarmike I will look at the branch, and get the tests / coverage passing.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 26, 2019
@crwilcox
Copy link
Contributor Author

The backend has deployed. So removing the 'do not merge'

@crwilcox crwilcox removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 29, 2019
@crwilcox crwilcox changed the title feature: Adding CollectionGroup queries (DO NOT MERGE) feature: Adding CollectionGroup queries Apr 29, 2019
@tseaver
Copy link
Contributor

tseaver commented Apr 29, 2019

@schmidt-sebastian I updated the "start at / end at" test as you requested in 115234c. However, for the "filters" test, when I change to filter on __name__ (which would match the Node test), the following query:

(Pdb) pp query._to_protobuf()
from {
  collection_id: "b-1556570226919"
  all_descendants: true
}
where {
  composite_filter {
    op: AND
    filters {
      field_filter {
        field {
          field_path: "__name__"
        }
        op: GREATER_THAN_OR_EQUAL
        value {
          string_value: "a/b"
        }
      }
    }
    filters {
      field_filter {
        field {
          field_path: "__name__"
        }
        op: LESS_THAN_OR_EQUAL
        value {
          string_value: "a/b0"
        }
      }
    }
  }
}

yields this error from the backend:

E   google.api_core.exceptions.InvalidArgument: 400 a filter on __name__ must be a document resource name

Note that this still doesn't pass, so remains skipped.
@wilhuff
Copy link

wilhuff commented Apr 29, 2019

In terms of the protos, I think you need to specify the value as reference_value. Note comments there on the format.

@tseaver tseaver added the api: firestore Issues related to the Firestore API. label Apr 30, 2019
@tseaver tseaver changed the title feature: Adding CollectionGroup queries Firestore: Add support for CollectionGroup queries. Apr 30, 2019
@tseaver tseaver changed the title Firestore: Add support for CollectionGroup queries. Firestore: add support for CollectionGroup queries. Apr 30, 2019
@tseaver
Copy link
Contributor

tseaver commented Apr 30, 2019

Unrelated pubsub failure.

@tseaver
Copy link
Contributor

tseaver commented Apr 30, 2019

Same oddity with logging due to pubsub.

@tseaver
Copy link
Contributor

tseaver commented Apr 30, 2019

@crwilcox, @busunkim96 please flip the CLA bit.

@busunkim96 busunkim96 added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. 🚨 This issue needs some love. labels Apr 30, 2019
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 30, 2019
@crwilcox crwilcox merged commit f5aec2d into master Apr 30, 2019
@crwilcox crwilcox deleted the firestore-collection-group branch April 30, 2019 18:28
tseaver referenced this pull request May 14, 2019
Skip the one for 'where', because it requires a custom index.
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. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants