Skip to content

Commit

Permalink
feat: add ApiScope and COLLECTION_RECURSIVE query_scope for Firestore…
Browse files Browse the repository at this point in the history
… index (#718)

* feat: add ApiScope and COLLECTION_RECURSIVE query_scope for Firestore index

PiperOrigin-RevId: 532955594

Source-Link: googleapis/googleapis@b4bb0e2

Source-Link: googleapis/googleapis-gen@57104e2
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 <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: meredithslota <meredithslota@google.com>
  • Loading branch information
3 people committed May 19, 2023
1 parent 2ea6774 commit d8de142
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
43 changes: 35 additions & 8 deletions google/cloud/firestore_admin_v1/types/index.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py
Expand Up @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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,
)
)
Expand All @@ -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


Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
)

Expand All @@ -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


Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d8de142

Please sign in to comment.