From d8de142b52ed0a7f9e299309173cc72b20184e5c Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 19 May 2023 15:44:50 -0400 Subject: [PATCH] feat: add ApiScope and COLLECTION_RECURSIVE query_scope for Firestore index (#718) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add ApiScope and COLLECTION_RECURSIVE query_scope for Firestore index PiperOrigin-RevId: 532955594 Source-Link: https://github.com/googleapis/googleapis/commit/b4bb0e2e2473016fedf9f8179db8cedad0b3ca5d Source-Link: https://github.com/googleapis/googleapis-gen/commit/57104e2a08b77d7c5f39eb5b972ce981d7822445 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTcxMDRlMmEwOGI3N2Q3YzVmMzllYjViOTcyY2U5ODFkNzgyMjQ0NSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot Co-authored-by: meredithslota --- .../cloud/firestore_admin_v1/types/index.py | 43 +++++++++++++++---- .../test_firestore_admin.py | 10 +++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/google/cloud/firestore_admin_v1/types/index.py b/google/cloud/firestore_admin_v1/types/index.py index e0f55f99f..e4447ee40 100644 --- a/google/cloud/firestore_admin_v1/types/index.py +++ b/google/cloud/firestore_admin_v1/types/index.py @@ -49,17 +49,19 @@ class Index(proto.Message): descended from a specific document, specified at query time, and that have the same collection id as this index. + api_scope (google.cloud.firestore_admin_v1.types.Index.ApiScope): + The API scope supported by this index. fields (MutableSequence[google.cloud.firestore_admin_v1.types.Index.IndexField]): The fields supported by this index. - For composite indexes, this is always 2 or more fields. The - last field entry is always for the field path ``__name__``. - If, on creation, ``__name__`` was not specified as the last - field, it will be added automatically with the same - direction as that of the last field defined. If the final - field in a composite index is not directional, the - ``__name__`` will be ordered ASCENDING (unless explicitly - specified). + For composite indexes, this requires a minimum of 2 and a + maximum of 100 fields. The last field entry is always for + the field path ``__name__``. If, on creation, ``__name__`` + was not specified as the last field, it will be added + automatically with the same direction as that of the last + field defined. If the final field in a composite index is + not directional, the ``__name__`` will be ordered ASCENDING + (unless explicitly specified). For single field indexes, this will always be exactly one entry with a field path equal to the field path of the @@ -87,10 +89,30 @@ class QueryScope(proto.Enum): specified allow queries against all collections that has the collection id specified by the index. + COLLECTION_RECURSIVE (3): + Include all the collections's ancestor in the + index. Only available for Datastore Mode + databases. """ QUERY_SCOPE_UNSPECIFIED = 0 COLLECTION = 1 COLLECTION_GROUP = 2 + COLLECTION_RECURSIVE = 3 + + class ApiScope(proto.Enum): + r"""API Scope defines the APIs (Firestore Native, or Firestore in + Datastore Mode) that are supported for queries. + + Values: + ANY_API (0): + The index can only be used by the Firestore + Native query API. This is the default. + DATASTORE_MODE_API (1): + The index can only be used by the Firestore + in Datastore Mode query API. + """ + ANY_API = 0 + DATASTORE_MODE_API = 1 class State(proto.Enum): r"""The state of an index. During index creation, an index will be in @@ -214,6 +236,11 @@ class ArrayConfig(proto.Enum): number=2, enum=QueryScope, ) + api_scope: ApiScope = proto.Field( + proto.ENUM, + number=5, + enum=ApiScope, + ) fields: MutableSequence[IndexField] = proto.RepeatedField( proto.MESSAGE, number=3, diff --git a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py index 11c2d569f..f7bb00bbe 100644 --- a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py +++ b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py @@ -1405,6 +1405,7 @@ def test_get_index(request_type, transport: str = "grpc"): call.return_value = index.Index( name="name_value", query_scope=index.Index.QueryScope.COLLECTION, + api_scope=index.Index.ApiScope.DATASTORE_MODE_API, state=index.Index.State.CREATING, ) response = client.get_index(request) @@ -1418,6 +1419,7 @@ def test_get_index(request_type, transport: str = "grpc"): assert isinstance(response, index.Index) assert response.name == "name_value" assert response.query_scope == index.Index.QueryScope.COLLECTION + assert response.api_scope == index.Index.ApiScope.DATASTORE_MODE_API assert response.state == index.Index.State.CREATING @@ -1457,6 +1459,7 @@ async def test_get_index_async( index.Index( name="name_value", query_scope=index.Index.QueryScope.COLLECTION, + api_scope=index.Index.ApiScope.DATASTORE_MODE_API, state=index.Index.State.CREATING, ) ) @@ -1471,6 +1474,7 @@ async def test_get_index_async( assert isinstance(response, index.Index) assert response.name == "name_value" assert response.query_scope == index.Index.QueryScope.COLLECTION + assert response.api_scope == index.Index.ApiScope.DATASTORE_MODE_API assert response.state == index.Index.State.CREATING @@ -3904,6 +3908,7 @@ def test_create_index_rest(request_type): request_init["index"] = { "name": "name_value", "query_scope": 1, + "api_scope": 1, "fields": [{"field_path": "field_path_value", "order": 1, "array_config": 1}], "state": 1, } @@ -4094,6 +4099,7 @@ def test_create_index_rest_bad_request( request_init["index"] = { "name": "name_value", "query_scope": 1, + "api_scope": 1, "fields": [{"field_path": "field_path_value", "order": 1, "array_config": 1}], "state": 1, } @@ -4551,6 +4557,7 @@ def test_get_index_rest(request_type): return_value = index.Index( name="name_value", query_scope=index.Index.QueryScope.COLLECTION, + api_scope=index.Index.ApiScope.DATASTORE_MODE_API, state=index.Index.State.CREATING, ) @@ -4568,6 +4575,7 @@ def test_get_index_rest(request_type): assert isinstance(response, index.Index) assert response.name == "name_value" assert response.query_scope == index.Index.QueryScope.COLLECTION + assert response.api_scope == index.Index.ApiScope.DATASTORE_MODE_API assert response.state == index.Index.State.CREATING @@ -5355,6 +5363,7 @@ def test_update_field_rest(request_type): { "name": "name_value", "query_scope": 1, + "api_scope": 1, "fields": [ { "field_path": "field_path_value", @@ -5553,6 +5562,7 @@ def test_update_field_rest_bad_request( { "name": "name_value", "query_scope": 1, + "api_scope": 1, "fields": [ { "field_path": "field_path_value",