2021-05-11 17:59:29 +08:00
|
|
|
import sys
|
2022-01-14 12:55:34 +08:00
|
|
|
import time
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-10-01 09:00:08 +08:00
|
|
|
from pymilvus import Collection
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
sys.path.append("..")
|
2021-10-01 09:00:08 +08:00
|
|
|
from check.func_check import ResponseChecker
|
2021-06-07 12:15:35 +08:00
|
|
|
from utils.api_request import api_request
|
2021-11-22 15:33:14 +08:00
|
|
|
from utils.util_log import test_log as log
|
2022-01-17 15:37:35 +08:00
|
|
|
from pymilvus.orm.types import CONSISTENCY_STRONG
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-07-28 19:35:22 +08:00
|
|
|
TIMEOUT = 20
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-09-26 15:17:56 +08:00
|
|
|
# keep small timeout for stability tests
|
|
|
|
# TIMEOUT = 5
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
class ApiCollectionWrapper:
|
2021-05-11 17:59:29 +08:00
|
|
|
collection = None
|
|
|
|
|
2022-01-14 18:21:34 +08:00
|
|
|
def init_collection(self, name, schema=None, using="default", shards_num=2, check_task=None, check_items=None, **kwargs):
|
2022-01-17 15:37:35 +08:00
|
|
|
consistency_level = kwargs.get("consistency_level", CONSISTENCY_STRONG)
|
2022-01-14 18:21:34 +08:00
|
|
|
kwargs.update({"consistency_level": consistency_level})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
""" In order to distinguish the same name of collection """
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-10-13 19:08:52 +08:00
|
|
|
res, is_succ = api_request([Collection, name, schema, using, shards_num], **kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
self.collection = res if is_succ else None
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ,
|
2021-10-13 19:08:52 +08:00
|
|
|
name=name, schema=schema, using=using, shards_num=shards_num, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def schema(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.schema
|
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-04 09:35:34 +08:00
|
|
|
return self.collection.description
|
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-04 09:35:34 +08:00
|
|
|
return self.collection.name
|
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):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.is_empty
|
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):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.num_entities
|
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 primary_field(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.primary_field
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-10-13 19:08:52 +08:00
|
|
|
@property
|
|
|
|
def _shards_num(self):
|
|
|
|
return self.collection._shards_num
|
|
|
|
|
2021-06-17 17:27:59 +08:00
|
|
|
def construct_from_dataframe(self, name, dataframe, check_task=None, check_items=None, **kwargs):
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, is_succ = api_request([Collection.construct_from_dataframe, name, dataframe], **kwargs)
|
2021-06-25 10:38:11 +08:00
|
|
|
self.collection = res[0] if is_succ else None
|
2021-06-17 17:27:59 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ,
|
|
|
|
name=name, dataframe=dataframe, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
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-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.drop], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def load(self, partition_names=None, 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-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.load, partition_names], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
partition_names=partition_names, **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-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.release], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
|
|
|
check_items, check, **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, partition_name=None, 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-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.insert, data, partition_name], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
dat=data, partition_name=partition_name,
|
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-17 17:27:59 +08:00
|
|
|
def search(self, data, anns_field, param, limit, expr=None,
|
2021-11-05 10:07:04 +08:00
|
|
|
partition_names=None, output_fields=None, timeout=None, round_decimal=-1,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-18 19:12:09 +08:00
|
|
|
res, check = api_request([self.collection.search, data, anns_field, param, limit,
|
2021-11-05 10:07:04 +08:00
|
|
|
expr, partition_names, output_fields, timeout, round_decimal], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
data=data, anns_field=anns_field, param=param, limit=limit,
|
2021-06-17 17:27:59 +08:00
|
|
|
expr=expr, partition_names=partition_names,
|
2021-06-05 10:25:34 +08:00
|
|
|
output_fields=output_fields,
|
|
|
|
timeout=timeout, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-17 13:43:57 +08:00
|
|
|
def query(self, expr, output_fields=None, partition_names=None, timeout=None, check_task=None, check_items=None,
|
|
|
|
**kwargs):
|
2022-01-14 18:21:34 +08:00
|
|
|
# time.sleep(5)
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
|
2021-06-17 13:43:57 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.collection.query, expr, output_fields, partition_names, timeout])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
|
|
|
expression=expr, partition_names=partition_names,
|
|
|
|
output_fields=output_fields,
|
|
|
|
timeout=timeout, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def partitions(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.partitions
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def partition(self, partition_name, check_task=None, check_items=None):
|
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.collection.partition, partition_name])
|
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
|
|
|
succ, partition_name=partition_name).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def has_partition(self, partition_name, check_task=None, check_items=None):
|
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.collection.has_partition, partition_name])
|
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
|
|
|
succ, partition_name=partition_name).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def drop_partition(self, partition_name, 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-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.drop_partition, partition_name], **kwargs)
|
2021-09-26 15:17:56 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, partition_name=partition_name,
|
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-07-26 15:51:20 +08:00
|
|
|
def create_partition(self, partition_name, check_task=None, check_items=None, description=""):
|
2021-06-10 11:46:49 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-07-26 15:51:20 +08:00
|
|
|
res, check = api_request([self.collection.create_partition, partition_name, description])
|
2021-06-10 11:46:49 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-07-26 15:51:20 +08:00
|
|
|
partition_name=partition_name).run()
|
2021-06-10 11:46:49 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def indexes(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.indexes
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def index(self, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.index])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def create_index(self, field_name, index_params, check_task=None, check_items=None, **kwargs):
|
2021-12-03 18:31:34 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT * 2)
|
2021-07-26 15:51:20 +08:00
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.create_index, field_name, index_params], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
|
|
|
field_name=field_name, index_params=index_params, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def has_index(self, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.has_index])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def drop_index(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-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.drop_index], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
2021-09-22 19:21:53 +08:00
|
|
|
|
2021-09-23 19:40:01 +08:00
|
|
|
def create_alias(self, alias_name, 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, check = api_request([self.collection.create_alias, alias_name], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
|
|
|
def drop_alias(self, alias_name, check_task=None, check_items=None, **kwargs):
|
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
2021-09-22 19:21:53 +08:00
|
|
|
|
2021-09-23 19:40:01 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.collection.drop_alias, alias_name], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
2021-09-22 19:21:53 +08:00
|
|
|
|
2021-09-23 19:40:01 +08:00
|
|
|
def alter_alias(self, alias_name, 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, check = api_request([self.collection.alter_alias, alias_name], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
2021-09-26 15:17:56 +08:00
|
|
|
|
|
|
|
def delete(self, expr, partition_name=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.collection.delete, expr, partition_name, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
2021-11-14 19:41:09 +08:00
|
|
|
|
|
|
|
def compact(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.collection.compact, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-11-22 15:33:14 +08:00
|
|
|
def get_compaction_state(self, timeout=None, check_task=None, check_items=None, **kwargs):
|
2021-11-14 19:41:09 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
2021-11-22 15:33:14 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.collection.get_compaction_state, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
|
|
|
return res, check_result
|
2021-11-14 19:41:09 +08:00
|
|
|
|
|
|
|
def get_compaction_plans(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.collection.get_compaction_plans, timeout], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
2021-11-22 15:33:14 +08:00
|
|
|
return res, check_result
|
|
|
|
|
|
|
|
def wait_for_compaction_completed(self, timeout=None, **kwargs):
|
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
res = self.collection.wait_for_compaction_completed(timeout, **kwargs)
|
|
|
|
log.debug(res)
|
|
|
|
return res
|