From 127ccf83163a28904360bfbf9edd09316edf3ab8 Mon Sep 17 00:00:00 2001 From: yah01 Date: Mon, 20 Nov 2023 16:29:23 +0800 Subject: [PATCH] enhance: remove partition existance check let server check whether partition existed, then we can get better error details. Signed-off-by: yah01 --- pymilvus/exceptions.py | 5 ---- pymilvus/orm/collection.py | 4 ---- pymilvus/orm/partition.py | 48 ++++++++++++-------------------------- pymilvus/orm/utility.py | 5 ++-- 4 files changed, 17 insertions(+), 45 deletions(-) diff --git a/pymilvus/exceptions.py b/pymilvus/exceptions.py index 5b1db4269..28e8c9a83 100644 --- a/pymilvus/exceptions.py +++ b/pymilvus/exceptions.py @@ -73,10 +73,6 @@ class DescribeCollectionException(MilvusException): """Raise when fail to describe collection""" -class PartitionNotExistException(MilvusException): - """Raise when partition doesn't exist""" - - class PartitionAlreadyExistException(MilvusException): """Raise when create an exsiting partition""" @@ -202,7 +198,6 @@ class ExceptionsMessage: NdArrayNotSupport = "Data type not support numpy.ndarray." TypeOfDataAndSchemaInconsistent = "The types of schema and data do not match." PartitionAlreadyExist = "Partition already exist." - PartitionNotExist = "Partition not exist." IndexNotExist = "Index doesn't exist." CollectionType = "The type of collection must be pymilvus.Collection." FieldsType = "The fields of schema must be type list." diff --git a/pymilvus/orm/collection.py b/pymilvus/orm/collection.py index 1def8b07e..a87d41629 100644 --- a/pymilvus/orm/collection.py +++ b/pymilvus/orm/collection.py @@ -31,7 +31,6 @@ ExceptionsMessage, IndexNotExistException, PartitionAlreadyExistException, - PartitionNotExistException, SchemaNotReadyException, ) from pymilvus.grpc_gen import schema_pb2 @@ -1069,7 +1068,6 @@ def drop_partition(self, partition_name: str, timeout: Optional[float] = None, * or error occur. Raises: - PartitionNotExistException: If the partition doesn't exists. MilvusException: If anything goes wrong. Examples: @@ -1087,8 +1085,6 @@ def drop_partition(self, partition_name: str, timeout: Optional[float] = None, * >>> collection.has_partition("comedy") False """ - if self.has_partition(partition_name, **kwargs) is False: - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) conn = self._get_connection() return conn.drop_partition(self._name, partition_name, timeout=timeout, **kwargs) diff --git a/pymilvus/orm/partition.py b/pymilvus/orm/partition.py index bc5f7796f..a84c08946 100644 --- a/pymilvus/orm/partition.py +++ b/pymilvus/orm/partition.py @@ -17,11 +17,7 @@ from pymilvus.client.abstract import SearchResult from pymilvus.client.types import Replica -from pymilvus.exceptions import ( - ExceptionsMessage, - MilvusException, - PartitionNotExistException, -) +from pymilvus.exceptions import MilvusException from .mutation import MutationResult @@ -163,7 +159,7 @@ def drop(self, timeout: Optional[float] = None, **kwargs): responds or an error occurs. Raises: - PartitionNotExistException: If the partitoin doesn't exist + MilvusException: If anything goes wrong. Examples: >>> from pymilvus import connections, Collection, Partition @@ -173,8 +169,6 @@ def drop(self, timeout: Optional[float] = None, **kwargs): >>> partition.drop() """ conn = self._get_connection() - if conn.has_partition(self._collection.name, self.name, timeout=timeout, **kwargs) is False: - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) return conn.drop_partition(self._collection.name, self.name, timeout=timeout, **kwargs) def load(self, replica_number: int = 1, timeout: Optional[float] = None, **kwargs): @@ -202,15 +196,13 @@ def load(self, replica_number: int = 1, timeout: Optional[float] = None, **kwarg >>> partition.load() """ conn = self._get_connection() - if conn.has_partition(self._collection.name, self.name, **kwargs): - return conn.load_partitions( - collection_name=self._collection.name, - partition_names=[self.name], - replica_number=replica_number, - timeout=timeout, - **kwargs, - ) - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) + return conn.load_partitions( + collection_name=self._collection.name, + partition_names=[self.name], + replica_number=replica_number, + timeout=timeout, + **kwargs, + ) def release(self, timeout: Optional[float] = None, **kwargs): """Release the partition data from memory. @@ -237,14 +229,12 @@ def release(self, timeout: Optional[float] = None, **kwargs): >>> partition.release() """ conn = self._get_connection() - if conn.has_partition(self._collection.name, self._name, **kwargs): - return conn.release_partitions( - collection_name=self._collection.name, - partition_names=[self.name], - timeout=timeout, - **kwargs, - ) - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) + return conn.release_partitions( + collection_name=self._collection.name, + partition_names=[self.name], + timeout=timeout, + **kwargs, + ) def insert( self, @@ -286,10 +276,6 @@ def insert( >>> res.insert_count 10 """ - conn = self._get_connection() - if conn.has_partition(self._collection.name, self.name, **kwargs) is False: - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) - return self._collection.insert(data, self.name, timeout=timeout, **kwargs) def delete(self, expr: str, timeout: Optional[float] = None, **kwargs): @@ -366,10 +352,6 @@ def upsert( >>> res.upsert_count 10 """ - conn = self._get_connection() - if conn.has_partition(self._collection.name, self.name, **kwargs) is False: - raise PartitionNotExistException(message=ExceptionsMessage.PartitionNotExist) - return self._collection.upsert(data, self.name, timeout=timeout, **kwargs) def search( diff --git a/pymilvus/orm/utility.py b/pymilvus/orm/utility.py index 7ef787021..4f522e7bf 100644 --- a/pymilvus/orm/utility.py +++ b/pymilvus/orm/utility.py @@ -189,7 +189,7 @@ def loading_progress( :return dict: {'loading_progress': '100%'} - :raises PartitionNotExistException: If partition doesn't exist. + :raises MilvusException: If anything goes wrong. :example: >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility >>> import pandas as pd @@ -281,8 +281,7 @@ def wait_for_loading_complete( :param timeout: The timeout for this method, unit: second :type timeout: int - :raises CollectionNotExistException: If collection doesn't exist. - :raises PartitionNotExistException: If partition doesn't exist. + :raises MilvusException: If anything goes wrong. :example: >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility