Skip to content

Commit

Permalink
enhance: remove partition existance check
Browse files Browse the repository at this point in the history
let server check whether partition existed,
then we can get better error details.

Signed-off-by: yah01 <[email protected]>
  • Loading branch information
yah01 committed Nov 20, 2023
1 parent 1428201 commit 127ccf8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 45 deletions.
5 changes: 0 additions & 5 deletions pymilvus/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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."
Expand Down
4 changes: 0 additions & 4 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
ExceptionsMessage,
IndexNotExistException,
PartitionAlreadyExistException,
PartitionNotExistException,
SchemaNotReadyException,
)
from pymilvus.grpc_gen import schema_pb2
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
48 changes: 15 additions & 33 deletions pymilvus/orm/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions pymilvus/orm/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 127ccf8

Please sign in to comment.