2021-05-11 17:59:29 +08:00
|
|
|
from pymilvus_orm import Partition
|
|
|
|
from pymilvus_orm.types import DataType
|
|
|
|
from pymilvus_orm.default_config import DefaultConfig
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append("..")
|
|
|
|
from check.param_check import *
|
|
|
|
from check.func_check import *
|
2021-05-13 12:17:15 +08:00
|
|
|
from utils.util_log import test_log as log
|
2021-05-11 17:59:29 +08:00
|
|
|
from common.common_type import *
|
|
|
|
|
|
|
|
|
2021-05-27 10:26:35 +08:00
|
|
|
class Error:
|
|
|
|
def __init__(self, error):
|
|
|
|
self.code = getattr(error, 'code', 99999)
|
|
|
|
self.message = getattr(error, 'message', str(error))
|
|
|
|
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
def partition_catch():
|
|
|
|
def wrapper(func):
|
|
|
|
def inner_wrapper(*args, **kwargs):
|
|
|
|
try:
|
2021-06-02 19:21:33 +08:00
|
|
|
res = func(*args, **kwargs)
|
|
|
|
log.debug("(func_res) Response : %s " % str(res))
|
|
|
|
return res, True
|
2021-05-11 17:59:29 +08:00
|
|
|
except Exception as e:
|
2021-06-02 19:21:33 +08:00
|
|
|
# log.info("exception: %s", e)
|
|
|
|
log.error("[Partition API Exception]%s: %s" % (str(func), str(e)))
|
2021-05-27 10:26:35 +08:00
|
|
|
return Error(e), False
|
2021-05-11 17:59:29 +08:00
|
|
|
return inner_wrapper
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
@partition_catch()
|
|
|
|
def func_req(_list, **kwargs):
|
|
|
|
if isinstance(_list, list):
|
|
|
|
func = _list[0]
|
|
|
|
if callable(func):
|
|
|
|
arg = []
|
|
|
|
if len(_list) > 1:
|
|
|
|
for a in _list[1:]:
|
|
|
|
arg.append(a)
|
2021-06-02 19:21:33 +08:00
|
|
|
log.debug("(func_req)[%s] Parameters ars arg: %s, kwargs: %s" % (str(func), str(arg), str(kwargs)))
|
2021-05-11 17:59:29 +08:00
|
|
|
return func(*arg, **kwargs)
|
|
|
|
return False, False
|
|
|
|
|
|
|
|
|
|
|
|
class ApiPartition:
|
|
|
|
partition = None
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def partition_init(self, collection, name, description="", check_res=None, check_params=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
|
|
|
|
res, check = func_req([Partition, collection, name, description], **kwargs)
|
|
|
|
self.partition = res if check is True else None
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check,
|
2021-05-27 10:26:35 +08:00
|
|
|
collection=collection, name=name, description=description,
|
|
|
|
is_empty=True, num_entities=0,
|
2021-05-11 17:59:29 +08:00
|
|
|
**kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def description(self, check_res=None, check_params=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.description])
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def name(self, check_res=None, check_params=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.name])
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def is_empty(self, check_res=None, check_params=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.is_empty])
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def num_entities(self, check_res=None, check_params=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.num_entities])
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def drop(self, check_res=None, check_params=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.drop], **kwargs)
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def load(self, field_names=None, index_names=None, check_res=None, check_params=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.load, field_names, index_names], **kwargs)
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check, field_names=field_names, index_names=index_names,
|
2021-05-11 17:59:29 +08:00
|
|
|
**kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def release(self, check_res=None, check_params=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.release], **kwargs)
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def insert(self, data, check_res=None, check_params=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.insert, data], **kwargs)
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check, data=data, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-05-14 09:27:41 +08:00
|
|
|
def search(self, data, anns_field, params, limit, expr=None, output_fields=None, check_res=None, check_params=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = func_req([self.partition.search, data, anns_field, params, limit, expr, output_fields], **kwargs)
|
2021-06-01 18:49:31 +08:00
|
|
|
check_result = CheckFunc(res, func_name, check_res, check_params, check, data=data, anns_field=anns_field, params=params,
|
2021-05-11 17:59:29 +08:00
|
|
|
limit=limit, expr=expr, output_fields=output_fields, **kwargs).run()
|
|
|
|
return res, check_result
|