diff --git a/CHANGELOG.md b/CHANGELOG.md index dbe2b9a..7c586ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tilebox-datasets/tests/test_timeseries.py b/tilebox-datasets/tests/test_timeseries.py index 656da10..cbe417f 100644 --- a/tilebox-datasets/tests/test_timeseries.py +++ b/tilebox-datasets/tests/test_timeseries.py @@ -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, ) @@ -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 @@ -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: diff --git a/tilebox-datasets/tilebox/datasets/aio/dataset.py b/tilebox-datasets/tilebox/datasets/aio/dataset.py index e4a4bc4..e61aa1b 100644 --- a/tilebox-datasets/tilebox/datasets/aio/dataset.py +++ b/tilebox-datasets/tilebox/datasets/aio/dataset.py @@ -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}" diff --git a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py index 6ac74d3..f611b85 100644 --- a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py +++ b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py @@ -25,7 +25,7 @@ from tilebox.datasets.datasetsv1 import core_pb2 as datasets_dot_v1_dot_core__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1d\x64\x61tasets/v1/collections.proto\x12\x0b\x64\x61tasets.v1\x1a\x16\x64\x61tasets/v1/core.proto\"]\n\x17\x43reateCollectionRequest\x12.\n\ndataset_id\x18\x01 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\x12\x12\n\x04name\x18\x02 \x01(\tR\x04name\"\xc1\x01\n\x1aGetCollectionByNameRequest\x12\'\n\x0f\x63ollection_name\x18\x01 \x01(\tR\x0e\x63ollectionName\x12+\n\x11with_availability\x18\x02 \x01(\x08R\x10withAvailability\x12\x1d\n\nwith_count\x18\x03 \x01(\x08R\twithCount\x12.\n\ndataset_id\x18\x04 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\"x\n\x1d\x44\x65leteCollectionByNameRequest\x12\'\n\x0f\x63ollection_name\x18\x01 \x01(\tR\x0e\x63ollectionName\x12.\n\ndataset_id\x18\x02 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\" \n\x1e\x44\x65leteCollectionByNameResponse\"\x94\x01\n\x16ListCollectionsRequest\x12.\n\ndataset_id\x18\x01 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\x12+\n\x11with_availability\x18\x02 \x01(\x08R\x10withAvailability\x12\x1d\n\nwith_count\x18\x03 \x01(\x08R\twithCount2\x98\x03\n\x11\x43ollectionService\x12W\n\x10\x43reateCollection\x12$.datasets.v1.CreateCollectionRequest\x1a\x1b.datasets.v1.CollectionInfo\"\x00\x12]\n\x13GetCollectionByName\x12\'.datasets.v1.GetCollectionByNameRequest\x1a\x1b.datasets.v1.CollectionInfo\"\x00\x12s\n\x16\x44\x65leteCollectionByName\x12*.datasets.v1.DeleteCollectionByNameRequest\x1a+.datasets.v1.DeleteCollectionByNameResponse\"\x00\x12V\n\x0fListCollections\x12#.datasets.v1.ListCollectionsRequest\x1a\x1c.datasets.v1.CollectionInfos\"\x00\x42\xb2\x01\n\x0f\x63om.datasets.v1B\x10\x43ollectionsProtoP\x01Z@github.com/tilebox/tilebox-go/protogen/go/datasets/v1;datasetsv1\xa2\x02\x03\x44XX\xaa\x02\x0b\x44\x61tasets.V1\xca\x02\x0b\x44\x61tasets\\V1\xe2\x02\x17\x44\x61tasets\\V1\\GPBMetadata\xea\x02\x0c\x44\x61tasets::V1b\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1d\x64\x61tasets/v1/collections.proto\x12\x0b\x64\x61tasets.v1\x1a\x16\x64\x61tasets/v1/core.proto\"]\n\x17\x43reateCollectionRequest\x12.\n\ndataset_id\x18\x01 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\x12\x12\n\x04name\x18\x02 \x01(\tR\x04name\"\xc1\x01\n\x1aGetCollectionByNameRequest\x12\'\n\x0f\x63ollection_name\x18\x01 \x01(\tR\x0e\x63ollectionName\x12+\n\x11with_availability\x18\x02 \x01(\x08R\x10withAvailability\x12\x1d\n\nwith_count\x18\x03 \x01(\x08R\twithCount\x12.\n\ndataset_id\x18\x04 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\"\x7f\n\x17\x44\x65leteCollectionRequest\x12\x34\n\rcollection_id\x18\x01 \x01(\x0b\x32\x0f.datasets.v1.IDR\x0c\x63ollectionId\x12.\n\ndataset_id\x18\x02 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\"\x1a\n\x18\x44\x65leteCollectionResponse\"\x94\x01\n\x16ListCollectionsRequest\x12.\n\ndataset_id\x18\x01 \x01(\x0b\x32\x0f.datasets.v1.IDR\tdatasetId\x12+\n\x11with_availability\x18\x02 \x01(\x08R\x10withAvailability\x12\x1d\n\nwith_count\x18\x03 \x01(\x08R\twithCount2\x86\x03\n\x11\x43ollectionService\x12W\n\x10\x43reateCollection\x12$.datasets.v1.CreateCollectionRequest\x1a\x1b.datasets.v1.CollectionInfo\"\x00\x12]\n\x13GetCollectionByName\x12\'.datasets.v1.GetCollectionByNameRequest\x1a\x1b.datasets.v1.CollectionInfo\"\x00\x12\x61\n\x10\x44\x65leteCollection\x12$.datasets.v1.DeleteCollectionRequest\x1a%.datasets.v1.DeleteCollectionResponse\"\x00\x12V\n\x0fListCollections\x12#.datasets.v1.ListCollectionsRequest\x1a\x1c.datasets.v1.CollectionInfos\"\x00\x42\xb2\x01\n\x0f\x63om.datasets.v1B\x10\x43ollectionsProtoP\x01Z@github.com/tilebox/tilebox-go/protogen/go/datasets/v1;datasetsv1\xa2\x02\x03\x44XX\xaa\x02\x0b\x44\x61tasets.V1\xca\x02\x0b\x44\x61tasets\\V1\xe2\x02\x17\x44\x61tasets\\V1\\GPBMetadata\xea\x02\x0c\x44\x61tasets::V1b\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -37,12 +37,12 @@ _globals['_CREATECOLLECTIONREQUEST']._serialized_end=163 _globals['_GETCOLLECTIONBYNAMEREQUEST']._serialized_start=166 _globals['_GETCOLLECTIONBYNAMEREQUEST']._serialized_end=359 - _globals['_DELETECOLLECTIONBYNAMEREQUEST']._serialized_start=361 - _globals['_DELETECOLLECTIONBYNAMEREQUEST']._serialized_end=481 - _globals['_DELETECOLLECTIONBYNAMERESPONSE']._serialized_start=483 - _globals['_DELETECOLLECTIONBYNAMERESPONSE']._serialized_end=515 - _globals['_LISTCOLLECTIONSREQUEST']._serialized_start=518 - _globals['_LISTCOLLECTIONSREQUEST']._serialized_end=666 - _globals['_COLLECTIONSERVICE']._serialized_start=669 - _globals['_COLLECTIONSERVICE']._serialized_end=1077 + _globals['_DELETECOLLECTIONREQUEST']._serialized_start=361 + _globals['_DELETECOLLECTIONREQUEST']._serialized_end=488 + _globals['_DELETECOLLECTIONRESPONSE']._serialized_start=490 + _globals['_DELETECOLLECTIONRESPONSE']._serialized_end=516 + _globals['_LISTCOLLECTIONSREQUEST']._serialized_start=519 + _globals['_LISTCOLLECTIONSREQUEST']._serialized_end=667 + _globals['_COLLECTIONSERVICE']._serialized_start=670 + _globals['_COLLECTIONSERVICE']._serialized_end=1060 # @@protoc_insertion_point(module_scope) diff --git a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi index 518c96c..9e52300 100644 --- a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi +++ b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi @@ -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: ... diff --git a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py index d95862b..c8e8b67 100644 --- a/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py +++ b/tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py @@ -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', @@ -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!') @@ -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, @@ -156,7 +156,7 @@ def GetCollectionByName(request, _registered_method=True) @staticmethod - def DeleteCollectionByName(request, + def DeleteCollection(request, target, options=(), channel_credentials=None, @@ -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, diff --git a/tilebox-datasets/tilebox/datasets/service.py b/tilebox-datasets/tilebox/datasets/service.py index 599269a..bfe3386 100644 --- a/tilebox-datasets/tilebox/datasets/service.py +++ b/tilebox-datasets/tilebox/datasets/service.py @@ -18,7 +18,7 @@ from tilebox.datasets.datasetsv1 import core_pb2 from tilebox.datasets.datasetsv1.collections_pb2 import ( CreateCollectionRequest, - DeleteCollectionByNameRequest, + DeleteCollectionRequest, GetCollectionByNameRequest, ListCollectionsRequest, ) @@ -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 diff --git a/tilebox-datasets/tilebox/datasets/sync/dataset.py b/tilebox-datasets/tilebox/datasets/sync/dataset.py index 968c85f..362d862 100644 --- a/tilebox-datasets/tilebox/datasets/sync/dataset.py +++ b/tilebox-datasets/tilebox/datasets/sync/dataset.py @@ -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}"