Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

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

## [0.37.1] - 2025-06-10

Expand Down
11 changes: 7 additions & 4 deletions tilebox-datasets/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from tilebox.datasets.data.uuid import uuid_message_to_uuid, uuid_to_uuid_message
from tilebox.datasets.datasetsv1.collections_pb2 import (
CreateCollectionRequest,
DeleteCollectionByNameRequest,
DeleteCollectionRequest,
GetCollectionByNameRequest,
ListCollectionsRequest,
)
Expand Down Expand Up @@ -292,8 +292,11 @@ def GetCollectionByName(self, req: GetCollectionByNameRequest) -> CollectionInfo
return self.collections[req.collection_name]
raise NotFoundError(f"Collection {req.collection_name} not found")

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

def ListCollections(self, req: ListCollectionsRequest) -> CollectionInfosMessage: # noqa: N802
_ = req
Expand Down Expand Up @@ -354,7 +357,7 @@ def get_collection(self, collection: CollectionClient) -> None:
def delete_collection(self, collection: CollectionClient) -> None:
self.count_collections -= 1
assert self.count_collections >= 0
self.dataset_client.delete_collection(collection.name)
self.dataset_client.delete_collection(collection)

@invariant()
def list_collections(self) -> None:
Expand Down
15 changes: 11 additions & 4 deletions tilebox-datasets/tilebox/datasets/aio/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ async def collection(self, name: str) -> "CollectionClient":

return CollectionClient(self, info)

async def delete_collection(self, name: str) -> None:
"""Delete a collection by its name.
async def delete_collection(self, collection: "str | UUID | CollectionClient") -> None:
"""Delete a collection.

Args:
name: The name of the collection to delete.
collection: The collection to delete or a collection name or a collection id.
"""
await self._service.delete_collection_by_name(self._dataset.id, name)
if isinstance(collection, CollectionClient):
collection_id = collection._collection.id
elif isinstance(collection, UUID):
collection_id = collection
else: # str
collection_id = (await self.collection(collection))._collection.id

await self._service.delete_collection(self._dataset.id, collection_id)

def __repr__(self) -> str:
return f"{self.name} [Timeseries Dataset]: {self._dataset.summary}"
Expand Down
18 changes: 9 additions & 9 deletions tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class GetCollectionByNameRequest(_message.Message):
dataset_id: _core_pb2.ID
def __init__(self, collection_name: _Optional[str] = ..., with_availability: bool = ..., with_count: bool = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...

class DeleteCollectionByNameRequest(_message.Message):
__slots__ = ("collection_name", "dataset_id")
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
class DeleteCollectionRequest(_message.Message):
__slots__ = ("collection_id", "dataset_id")
COLLECTION_ID_FIELD_NUMBER: _ClassVar[int]
DATASET_ID_FIELD_NUMBER: _ClassVar[int]
collection_name: str
collection_id: _core_pb2.ID
dataset_id: _core_pb2.ID
def __init__(self, collection_name: _Optional[str] = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
def __init__(self, collection_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...

class DeleteCollectionByNameResponse(_message.Message):
class DeleteCollectionResponse(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def __init__(self, channel):
request_serializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.SerializeToString,
response_deserializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.FromString,
_registered_method=True)
self.DeleteCollectionByName = channel.unary_unary(
'/datasets.v1.CollectionService/DeleteCollectionByName',
request_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
response_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
self.DeleteCollection = channel.unary_unary(
'/datasets.v1.CollectionService/DeleteCollection',
request_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.SerializeToString,
response_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.FromString,
_registered_method=True)
self.ListCollections = channel.unary_unary(
'/datasets.v1.CollectionService/ListCollections',
Expand All @@ -54,7 +54,7 @@ def GetCollectionByName(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def DeleteCollectionByName(self, request, context):
def DeleteCollection(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
Expand All @@ -79,10 +79,10 @@ def add_CollectionServiceServicer_to_server(servicer, server):
request_deserializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.FromString,
response_serializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.SerializeToString,
),
'DeleteCollectionByName': grpc.unary_unary_rpc_method_handler(
servicer.DeleteCollectionByName,
request_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.FromString,
response_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.SerializeToString,
'DeleteCollection': grpc.unary_unary_rpc_method_handler(
servicer.DeleteCollection,
request_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.FromString,
response_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.SerializeToString,
),
'ListCollections': grpc.unary_unary_rpc_method_handler(
servicer.ListCollections,
Expand Down Expand Up @@ -156,7 +156,7 @@ def GetCollectionByName(request,
_registered_method=True)

@staticmethod
def DeleteCollectionByName(request,
def DeleteCollection(request,
target,
options=(),
channel_credentials=None,
Expand All @@ -169,9 +169,9 @@ def DeleteCollectionByName(request,
return grpc.experimental.unary_unary(
request,
target,
'/datasets.v1.CollectionService/DeleteCollectionByName',
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
'/datasets.v1.CollectionService/DeleteCollection',
datasets_dot_v1_dot_collections__pb2.DeleteCollectionRequest.SerializeToString,
datasets_dot_v1_dot_collections__pb2.DeleteCollectionResponse.FromString,
options,
channel_credentials,
insecure,
Expand Down
14 changes: 8 additions & 6 deletions tilebox-datasets/tilebox/datasets/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from tilebox.datasets.datasetsv1 import core_pb2
from tilebox.datasets.datasetsv1.collections_pb2 import (
CreateCollectionRequest,
DeleteCollectionByNameRequest,
DeleteCollectionRequest,
GetCollectionByNameRequest,
ListCollectionsRequest,
)
Expand Down Expand Up @@ -84,15 +84,17 @@ def create_collection(self, dataset_id: UUID, name: str) -> Promise[CollectionIn
req = CreateCollectionRequest(dataset_id=uuid_to_uuid_message(dataset_id), name=name)
return Promise.resolve(self._collection_service.CreateCollection(req)).then(CollectionInfo.from_message)

def delete_collection_by_name(self, dataset_id: UUID, name: str) -> Promise[None]:
"""Delete a collection in a dataset by name.
def delete_collection(self, dataset_id: UUID, collection_id: UUID) -> Promise[None]:
"""Delete a collection in a dataset by id.

Args:
dataset_id: The id of the dataset to delete the collection from.
name: The name of the collection to delete.
collection_id: The id of the collection to delete.
"""
req = DeleteCollectionByNameRequest(dataset_id=uuid_to_uuid_message(dataset_id), collection_name=name)
return Promise.resolve(self._collection_service.DeleteCollectionByName(req))
req = DeleteCollectionRequest(
dataset_id=uuid_to_uuid_message(dataset_id), collection_id=uuid_to_uuid_message(collection_id)
)
return Promise.resolve(self._collection_service.DeleteCollection(req))

def get_collections(
self, dataset_id: UUID, with_availability: bool = True, with_count: bool = False
Expand Down
15 changes: 11 additions & 4 deletions tilebox-datasets/tilebox/datasets/sync/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,20 @@ def collection(self, name: str) -> "CollectionClient":

return CollectionClient(self, info)

def delete_collection(self, name: str) -> None:
"""Delete a collection by its name.
def delete_collection(self, collection: "str | UUID | CollectionClient") -> None:
"""Delete a collection.

Args:
name: The name of the collection to delete.
collection: The collection to delete or a collection name or a collection id.
"""
self._service.delete_collection_by_name(self._dataset.id, name).get()
if isinstance(collection, CollectionClient):
collection_id = collection._collection.id
elif isinstance(collection, UUID):
collection_id = collection
else: # str
collection_id = self.collection(collection)._collection.id

self._service.delete_collection(self._dataset.id, collection_id).get()

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