Skip to content

Commit 459cd73

Browse files
Delete a collection by name, id, or instance (#4)
1 parent abdbf12 commit 459cd73

File tree

8 files changed

+66
-47
lines changed

8 files changed

+66
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- `tilebox-datasets`: Added `delete_collection` method to `DatasetClient` to delete a collection by name.
12+
- `tilebox-datasets`: Added `delete_collection` method to `DatasetClient` to delete a collection.
1313

1414
## [0.37.1] - 2025-06-10
1515

tilebox-datasets/tests/test_timeseries.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from tilebox.datasets.data.uuid import uuid_message_to_uuid, uuid_to_uuid_message
2929
from tilebox.datasets.datasetsv1.collections_pb2 import (
3030
CreateCollectionRequest,
31-
DeleteCollectionByNameRequest,
31+
DeleteCollectionRequest,
3232
GetCollectionByNameRequest,
3333
ListCollectionsRequest,
3434
)
@@ -292,8 +292,11 @@ def GetCollectionByName(self, req: GetCollectionByNameRequest) -> CollectionInfo
292292
return self.collections[req.collection_name]
293293
raise NotFoundError(f"Collection {req.collection_name} not found")
294294

295-
def DeleteCollectionByName(self, req: DeleteCollectionByNameRequest) -> None: # noqa: N802
296-
del self.collections[req.collection_name]
295+
def DeleteCollection(self, req: DeleteCollectionRequest) -> None: # noqa: N802
296+
for collection in self.collections.values():
297+
if collection.collection.id == req.collection_id:
298+
del self.collections[collection.collection.name]
299+
return
297300

298301
def ListCollections(self, req: ListCollectionsRequest) -> CollectionInfosMessage: # noqa: N802
299302
_ = req
@@ -354,7 +357,7 @@ def get_collection(self, collection: CollectionClient) -> None:
354357
def delete_collection(self, collection: CollectionClient) -> None:
355358
self.count_collections -= 1
356359
assert self.count_collections >= 0
357-
self.dataset_client.delete_collection(collection.name)
360+
self.dataset_client.delete_collection(collection)
358361

359362
@invariant()
360363
def list_collections(self) -> None:

tilebox-datasets/tilebox/datasets/aio/dataset.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,20 @@ async def collection(self, name: str) -> "CollectionClient":
127127

128128
return CollectionClient(self, info)
129129

130-
async def delete_collection(self, name: str) -> None:
131-
"""Delete a collection by its name.
130+
async def delete_collection(self, collection: "str | UUID | CollectionClient") -> None:
131+
"""Delete a collection.
132132
133133
Args:
134-
name: The name of the collection to delete.
134+
collection: The collection to delete or a collection name or a collection id.
135135
"""
136-
await self._service.delete_collection_by_name(self._dataset.id, name)
136+
if isinstance(collection, CollectionClient):
137+
collection_id = collection._collection.id
138+
elif isinstance(collection, UUID):
139+
collection_id = collection
140+
else: # str
141+
collection_id = (await self.collection(collection))._collection.id
142+
143+
await self._service.delete_collection(self._dataset.id, collection_id)
137144

138145
def __repr__(self) -> str:
139146
return f"{self.name} [Timeseries Dataset]: {self._dataset.summary}"

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class GetCollectionByNameRequest(_message.Message):
2525
dataset_id: _core_pb2.ID
2626
def __init__(self, collection_name: _Optional[str] = ..., with_availability: bool = ..., with_count: bool = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
2727

28-
class DeleteCollectionByNameRequest(_message.Message):
29-
__slots__ = ("collection_name", "dataset_id")
30-
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
28+
class DeleteCollectionRequest(_message.Message):
29+
__slots__ = ("collection_id", "dataset_id")
30+
COLLECTION_ID_FIELD_NUMBER: _ClassVar[int]
3131
DATASET_ID_FIELD_NUMBER: _ClassVar[int]
32-
collection_name: str
32+
collection_id: _core_pb2.ID
3333
dataset_id: _core_pb2.ID
34-
def __init__(self, collection_name: _Optional[str] = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
34+
def __init__(self, collection_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
3535

36-
class DeleteCollectionByNameResponse(_message.Message):
36+
class DeleteCollectionResponse(_message.Message):
3737
__slots__ = ()
3838
def __init__(self) -> None: ...
3939

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def __init__(self, channel):
2626
request_serializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.SerializeToString,
2727
response_deserializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.FromString,
2828
_registered_method=True)
29-
self.DeleteCollectionByName = channel.unary_unary(
30-
'/datasets.v1.CollectionService/DeleteCollectionByName',
31-
request_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
32-
response_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
29+
self.DeleteCollection = channel.unary_unary(
30+
'/datasets.v1.CollectionService/DeleteCollection',
31+
request_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.SerializeToString,
32+
response_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.FromString,
3333
_registered_method=True)
3434
self.ListCollections = channel.unary_unary(
3535
'/datasets.v1.CollectionService/ListCollections',
@@ -54,7 +54,7 @@ def GetCollectionByName(self, request, context):
5454
context.set_details('Method not implemented!')
5555
raise NotImplementedError('Method not implemented!')
5656

57-
def DeleteCollectionByName(self, request, context):
57+
def DeleteCollection(self, request, context):
5858
"""Missing associated documentation comment in .proto file."""
5959
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
6060
context.set_details('Method not implemented!')
@@ -79,10 +79,10 @@ def add_CollectionServiceServicer_to_server(servicer, server):
7979
request_deserializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.FromString,
8080
response_serializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.SerializeToString,
8181
),
82-
'DeleteCollectionByName': grpc.unary_unary_rpc_method_handler(
83-
servicer.DeleteCollectionByName,
84-
request_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.FromString,
85-
response_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.SerializeToString,
82+
'DeleteCollection': grpc.unary_unary_rpc_method_handler(
83+
servicer.DeleteCollection,
84+
request_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.FromString,
85+
response_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.SerializeToString,
8686
),
8787
'ListCollections': grpc.unary_unary_rpc_method_handler(
8888
servicer.ListCollections,
@@ -156,7 +156,7 @@ def GetCollectionByName(request,
156156
_registered_method=True)
157157

158158
@staticmethod
159-
def DeleteCollectionByName(request,
159+
def DeleteCollection(request,
160160
target,
161161
options=(),
162162
channel_credentials=None,
@@ -169,9 +169,9 @@ def DeleteCollectionByName(request,
169169
return grpc.experimental.unary_unary(
170170
request,
171171
target,
172-
'/datasets.v1.CollectionService/DeleteCollectionByName',
173-
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
174-
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
172+
'/datasets.v1.CollectionService/DeleteCollection',
173+
datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.SerializeToString,
174+
datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.FromString,
175175
options,
176176
channel_credentials,
177177
insecure,

tilebox-datasets/tilebox/datasets/service.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from tilebox.datasets.datasetsv1 import core_pb2
1919
from tilebox.datasets.datasetsv1.collections_pb2 import (
2020
CreateCollectionRequest,
21-
DeleteCollectionByNameRequest,
21+
DeleteCollectionRequest,
2222
GetCollectionByNameRequest,
2323
ListCollectionsRequest,
2424
)
@@ -84,15 +84,17 @@ def create_collection(self, dataset_id: UUID, name: str) -> Promise[CollectionIn
8484
req = CreateCollectionRequest(dataset_id=uuid_to_uuid_message(dataset_id), name=name)
8585
return Promise.resolve(self._collection_service.CreateCollection(req)).then(CollectionInfo.from_message)
8686

87-
def delete_collection_by_name(self, dataset_id: UUID, name: str) -> Promise[None]:
88-
"""Delete a collection in a dataset by name.
87+
def delete_collection(self, dataset_id: UUID, collection_id: UUID) -> Promise[None]:
88+
"""Delete a collection in a dataset by id.
8989
9090
Args:
9191
dataset_id: The id of the dataset to delete the collection from.
92-
name: The name of the collection to delete.
92+
collection_id: The id of the collection to delete.
9393
"""
94-
req = DeleteCollectionByNameRequest(dataset_id=uuid_to_uuid_message(dataset_id), collection_name=name)
95-
return Promise.resolve(self._collection_service.DeleteCollectionByName(req))
94+
req = DeleteCollectionRequest(
95+
dataset_id=uuid_to_uuid_message(dataset_id), collection_id=uuid_to_uuid_message(collection_id)
96+
)
97+
return Promise.resolve(self._collection_service.DeleteCollection(req))
9698

9799
def get_collections(
98100
self, dataset_id: UUID, with_availability: bool = True, with_count: bool = False

tilebox-datasets/tilebox/datasets/sync/dataset.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,20 @@ def collection(self, name: str) -> "CollectionClient":
124124

125125
return CollectionClient(self, info)
126126

127-
def delete_collection(self, name: str) -> None:
128-
"""Delete a collection by its name.
127+
def delete_collection(self, collection: "str | UUID | CollectionClient") -> None:
128+
"""Delete a collection.
129129
130130
Args:
131-
name: The name of the collection to delete.
131+
collection: The collection to delete or a collection name or a collection id.
132132
"""
133-
self._service.delete_collection_by_name(self._dataset.id, name).get()
133+
if isinstance(collection, CollectionClient):
134+
collection_id = collection._collection.id
135+
elif isinstance(collection, UUID):
136+
collection_id = collection
137+
else: # str
138+
collection_id = self.collection(collection)._collection.id
139+
140+
self._service.delete_collection(self._dataset.id, collection_id).get()
134141

135142
def __repr__(self) -> str:
136143
return f"{self.name} [Timeseries Dataset]: {self._dataset.summary}"

0 commit comments

Comments
 (0)