2021-05-11 17:59:29 +08:00
|
|
|
import sys
|
2022-05-05 18:15:51 +08:00
|
|
|
from numpy import NaN
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-10-04 20:02:01 +08:00
|
|
|
from pymilvus import Partition
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
sys.path.append("..")
|
2021-10-04 20:02:01 +08:00
|
|
|
from check.func_check import ResponseChecker
|
2021-06-07 12:15:35 +08:00
|
|
|
from utils.api_request import api_request
|
2022-05-05 18:15:51 +08:00
|
|
|
from common.common_func import param_info
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-08-03 11:01:25 +08:00
|
|
|
TIMEOUT = 20
|
2021-07-26 15:51:20 +08:00
|
|
|
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
class ApiPartitionWrapper:
|
2021-05-11 17:59:29 +08:00
|
|
|
partition = None
|
|
|
|
|
2021-06-07 12:15:35 +08:00
|
|
|
def init_partition(self, collection, name, description="",
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
""" In order to distinguish the same name of partition """
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
response, is_succ = api_request([Partition, collection, name, description], **kwargs)
|
|
|
|
self.partition = response if is_succ is True else None
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(response, func_name, check_task, check_items, is_succ,
|
2021-06-05 10:25:34 +08:00
|
|
|
**kwargs).run()
|
2021-06-07 12:15:35 +08:00
|
|
|
return response, check_result
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def description(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.description if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def name(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.name if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def is_empty(self):
|
2022-08-10 10:36:37 +08:00
|
|
|
self.flush()
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.is_empty if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def num_entities(self):
|
2022-08-10 10:36:37 +08:00
|
|
|
self.flush()
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.num_entities if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def drop(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.drop], **kwargs)
|
2021-06-17 11:49:57 +08:00
|
|
|
check_result = ResponseChecker(res, func_name,
|
|
|
|
check_task, check_items, succ, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2022-05-05 18:15:51 +08:00
|
|
|
def load(self, replica_number=NaN, timeout=None, check_task=None, check_items=None, **kwargs):
|
2022-04-26 11:31:49 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
2022-05-05 18:15:51 +08:00
|
|
|
replica_number = param_info.param_replica_num if replica_number is NaN else replica_number
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2022-04-26 11:31:49 +08:00
|
|
|
res, succ = api_request([self.partition.load, replica_number, timeout], **kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ,
|
2021-06-05 10:25:34 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def release(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.release], **kwargs)
|
2022-08-10 10:36:37 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
|
|
|
check_items, is_succ=succ,
|
|
|
|
**kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
|
|
|
def flush(self, check_task=None, check_items=None, **kwargs):
|
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, succ = api_request([self.partition.flush], **kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ,
|
2021-06-07 12:15:35 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def insert(self, data, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.insert, data], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ, data=data,
|
2021-06-07 12:15:35 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 12:15:35 +08:00
|
|
|
def search(self, data, anns_field, params, limit, expr=None, output_fields=None,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.search, data, anns_field, params,
|
|
|
|
limit, expr, output_fields], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items,
|
2021-06-07 12:15:35 +08:00
|
|
|
is_succ=succ, data=data, anns_field=anns_field,
|
|
|
|
params=params, limit=limit, expr=expr,
|
|
|
|
output_fields=output_fields, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
2022-02-09 09:49:46 +08:00
|
|
|
|
2022-04-26 11:31:49 +08:00
|
|
|
def query(self, expr, output_fields=None, timeout=None, check_task=None, check_items=None, **kwargs):
|
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.partition.query, expr, output_fields, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
|
|
|
expression=expr, output_fields=output_fields,
|
|
|
|
timeout=timeout, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2022-02-09 09:49:46 +08:00
|
|
|
def delete(self, expr, check_task=None, check_items=None, **kwargs):
|
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, succ = api_request([self.partition.delete, expr], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
|
|
|
check_items, is_succ=succ, expr=expr,
|
|
|
|
**kwargs).run()
|
|
|
|
return res, check_result
|
2022-04-26 11:31:49 +08:00
|
|
|
|
|
|
|
def get_replicas(self, timeout=None, check_task=None, check_items=None, **kwargs):
|
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.partition.get_replicas, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|