Skip to content

Commit

Permalink
Add func check of output fields and modify cases (#25510)
Browse files Browse the repository at this point in the history
Signed-off-by: nico <cheng.yuan@zilliz.com>
  • Loading branch information
NicoYuan1986 committed Jul 12, 2023
1 parent 356b244 commit 8b7bd87
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 323 deletions.
6 changes: 3 additions & 3 deletions tests/python_client/base/client_base.py
Expand Up @@ -196,7 +196,7 @@ def insert_data_general(self, prefix="test", insert_data=False, nb=ct.default_nb

def init_collection_general(self, prefix="test", insert_data=False, nb=ct.default_nb,
partition_num=0, is_binary=False, is_all_data_type=False,
auto_id=False, dim=ct.default_dim, is_index=False,
auto_id=False, dim=ct.default_dim, is_index=True,
primary_field=ct.default_int64_field_name, is_flush=True, name=None,
enable_dynamic_field=False, with_json=True, **kwargs):
"""
Expand Down Expand Up @@ -243,13 +243,13 @@ def init_collection_general(self, prefix="test", insert_data=False, nb=ct.defaul
assert collection_w.is_empty is False
assert collection_w.num_entities == nb
# This condition will be removed after auto index feature
if not is_index:
if is_index:
if is_binary:
collection_w.create_index(ct.default_binary_vec_field_name, ct.default_bin_flat_index)
else:
collection_w.create_index(ct.default_float_vec_field_name, ct.default_flat_index)
collection_w.load()
elif not is_index:
elif is_index:
if is_binary:
collection_w.create_index(ct.default_binary_vec_field_name, ct.default_bin_flat_index)
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/python_client/check/func_check.py
Expand Up @@ -287,6 +287,12 @@ def check_search_results(search_res, func_name, check_items):
if check_items["_async"]:
search_res.done()
search_res = search_res.result()
if check_items.get("output_fields", None):
assert set(search_res[0][0].entity.fields) == set(check_items["output_fields"])
log.info('search_results_check: Output fields of query searched is correct')
if check_items.get("original_entities", None):
original_entities = check_items["original_entities"][0]
pc.output_field_value_check(search_res, original_entities)
if len(search_res) != check_items["nq"]:
log.error("search_results_check: Numbers of query searched (%d) "
"is not equal with expected (%d)"
Expand Down
20 changes: 20 additions & 0 deletions tests/python_client/check/param_check.py
Expand Up @@ -224,3 +224,23 @@ def equal_entities_list(exp, actual, primary_field, with_vec=False):
except Exception as ex:
log.error(ex)
return True if len(exp) == 0 else False


def output_field_value_check(search_res, original):
"""
check if the value of output fields is correct
:param search_res: the search result of specific output fields
:param original: the data in the collection
:return: True or False
"""
limit = len(search_res[0])
for i in range(limit):
entity = eval(str(search_res[0][i]).split('entity: ', 1)[1])
_id = search_res[0][i].id
for field in entity.keys():
if isinstance(entity[field], list):
for order in range(0, len(entity[field]), 4):
assert abs(original[field][_id][order] - entity[field][order]) < ct.epsilon
else:
assert original[field][_id] == entity[field]
return True
8 changes: 8 additions & 0 deletions tests/python_client/common/common_func.py
Expand Up @@ -1016,3 +1016,11 @@ def install_milvus_operator_specific_config(namespace, milvus_mode, release_name
raise MilvusException(message=f'Milvus healthy timeout 1800s')

return host


def get_wildcard_output_field_names(collection_w, output_fields):
all_fields = [field.name for field in collection_w.schema.fields]
if "*" in output_fields:
output_fields.remove("*")
output_fields.extend(all_fields)
return output_fields
8 changes: 4 additions & 4 deletions tests/python_client/testcases/test_collection.py
Expand Up @@ -2543,7 +2543,7 @@ def test_load_collection_without_creating_index(self):
method: create a collection without index, then load
expected: raise exception
"""
collection_w = self.init_collection_general(prefix, True, is_index=True)[0]
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
collection_w.load(check_task=CheckTasks.err_res,
check_items={"err_code": 1,
"err_msg": "index not exist"})
Expand Down Expand Up @@ -2581,7 +2581,7 @@ def test_release_partition_during_searching(self):
"""
self._connect()
partition_num = 1
collection_w = self.init_collection_general(prefix, True, 10, partition_num, is_index=True)[0]
collection_w = self.init_collection_general(prefix, True, 10, partition_num, is_index=False)[0]
collection_w.create_index(ct.default_float_vec_field_name, index_params=ct.default_flat_index)
par = collection_w.partitions
par_name = par[partition_num].name
Expand All @@ -2607,7 +2607,7 @@ def test_release_indexed_collection_during_searching(self):
"""
self._connect()
partition_num = 1
collection_w = self.init_collection_general(prefix, True, 10, partition_num, is_index=True)[0]
collection_w = self.init_collection_general(prefix, True, 10, partition_num, is_index=False)[0]
collection_w.create_index(ct.default_float_vec_field_name, index_params=ct.default_flat_index)
par = collection_w.partitions
par_name = par[partition_num].name
Expand Down Expand Up @@ -2662,7 +2662,7 @@ def test_load_partition_after_index_binary(self, binary_index, metric_type):
self._connect()
partition_num = 1
collection_w = self.init_collection_general(prefix, True, ct.default_nb, partition_num,
is_binary=True, is_index=True)[0]
is_binary=True, is_index=False)[0]

# for metric_type in ct.binary_metrics:
binary_index["metric_type"] = metric_type
Expand Down
4 changes: 2 additions & 2 deletions tests/python_client/testcases/test_delete.py
Expand Up @@ -321,7 +321,7 @@ def test_delete_after_index(self):
expected: assert index and deleted id not in search result
"""
# create collection, insert tmp_nb, flush and load
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=False)[0:2]

# create index
index_params = {"index_type": "IVF_SQ8",
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def test_delete_all_index_with_string(self):
expected: assert index and deleted id not in search result
"""
# create collection, insert tmp_nb, flush and load
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=True,
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=False,
primary_field=ct.default_string_field_name)[0:2]

# create index
Expand Down
17 changes: 7 additions & 10 deletions tests/python_client/testcases/test_index.py
Expand Up @@ -225,7 +225,7 @@ def test_index_create_indexes_for_different_fields(self):
method: create two different indexes with default index name
expected: create successfully
"""
collection_w = self.init_collection_general(prefix, True, is_index=True)[0]
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
collection_w.create_index(default_field_name, default_index)
collection_w.create_index(ct.default_int64_field_name, {})
Expand All @@ -237,7 +237,7 @@ def test_index_create_on_scalar_field(self):
method: create index on scalar field and load
expected: raise exception
"""
collection_w = self.init_collection_general(prefix, True, is_index=True)[0]
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
collection_w.create_index(ct.default_int64_field_name, {})
collection_w.load(check_task=CheckTasks.err_res,
check_items={ct.err_code: 1, ct.err_msg: "there is no vector index on collection, "
Expand Down Expand Up @@ -1259,10 +1259,7 @@ def test_drop_index_without_release(self):
2. drop the index
expected: raise exception
"""
collection_w = self.init_collection_general(prefix, True, is_index=True)[0]
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
collection_w.create_index("float_vector", default_index)
collection_w.load()
collection_w = self.init_collection_general(prefix, True)[0]
collection_w.drop_index(check_task=CheckTasks.err_res,
check_items={"err_code": 1,
"err_msg": "index cannot be dropped, collection is "
Expand Down Expand Up @@ -1853,7 +1850,7 @@ def test_create_autoindex_with_no_params(self):
method: create index with only one field name
expected: create successfully
"""
collection_w = self.init_collection_general(prefix, is_index=True)[0]
collection_w = self.init_collection_general(prefix, is_index=False)[0]
collection_w.create_index(field_name)
actual_index_params = collection_w.index()[0].params
assert default_autoindex_params == actual_index_params
Expand All @@ -1866,7 +1863,7 @@ def test_create_autoindex_with_params(self, index_params):
method: create index with different params
expected: create successfully
"""
collection_w = self.init_collection_general(prefix, is_index=True)[0]
collection_w = self.init_collection_general(prefix, is_index=False)[0]
collection_w.create_index(field_name, index_params)
actual_index_params = collection_w.index()[0].params
log.info(collection_w.index()[0].params)
Expand All @@ -1885,7 +1882,7 @@ def test_create_autoindex_with_invalid_params(self):
method: create index with invalid params
expected: raise exception
"""
collection_w = self.init_collection_general(prefix, is_index=True)[0]
collection_w = self.init_collection_general(prefix, is_index=False)[0]
index_params = {"metric_type": "L2", "nlist": "1024", "M": "100"}
collection_w.create_index(field_name, index_params,
check_task=CheckTasks.err_res,
Expand All @@ -1900,7 +1897,7 @@ def test_create_autoindex_on_binary_vectors(self):
method: create index on binary vectors
expected: raise exception
"""
collection_w = self.init_collection_general(prefix, is_binary=True, is_index=True)[0]
collection_w = self.init_collection_general(prefix, is_binary=True, is_index=False)[0]
collection_w.create_index(binary_field_name, {},
check_task=CheckTasks.err_res,
check_items={"err_code": 1,
Expand Down
24 changes: 8 additions & 16 deletions tests/python_client/testcases/test_query.py
Expand Up @@ -780,13 +780,11 @@ def test_query_output_fields_part_scale_wildcard(self):
expected: verify query result
"""
# init collection with fields: int64, float, float_vec
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True)[0:2]
df = vectors[0]

# query with output_fields=["*", float_vector)
res = df.iloc[:2, :4].to_dict('records')
collection_w.create_index(ct.default_float_vec_field_name, index_params=ct.default_flat_index)
collection_w.load()
collection_w.query(default_term_expr, output_fields=["*", ct.default_float_vec_field_name],
check_task=CheckTasks.check_query_results,
check_items={exp_res: res, "with_vec": True})
Expand Down Expand Up @@ -1338,13 +1336,7 @@ def test_query_after_index(self):
3. query
expected: query result is correct
"""
collection_w, vectors, binary_raw_vectors = self.init_collection_general(prefix, insert_data=True, is_index=True)[0:3]

default_field_name = ct.default_float_vec_field_name
collection_w.create_index(default_field_name, default_index_params)

collection_w.load()

collection_w, vectors, binary_raw_vectors = self.init_collection_general(prefix, insert_data=True)[0:3]
int_values = [0]
term_expr = f'{ct.default_int64_field_name} in {int_values}'
check_vec = vectors[0].iloc[:, [0]][0:len(int_values)].to_dict('records')
Expand Down Expand Up @@ -1405,7 +1397,7 @@ def test_query_output_binary_vec_field_after_index(self):
method: create index and specify vec field as output field
expected: return primary field and vec field
"""
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_binary=True, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_binary=True, is_index=False)[0:2]
fields = [ct.default_int64_field_name, ct.default_binary_vec_field_name]
collection_w.create_index(ct.default_binary_vec_field_name, binary_index_params)
assert collection_w.has_index()[0]
Expand Down Expand Up @@ -1589,7 +1581,7 @@ def test_query_string_expr_with_binary(self):
method: query string expr with binary
expected: verify query successfully
"""
collection_w, vectors= self.init_collection_general(prefix, insert_data=True, is_binary=True, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_binary=True, is_index=False)[0:2]
collection_w.create_index(ct.default_binary_vec_field_name, binary_index_params)
collection_w.load()
assert collection_w.has_index()[0]
Expand Down Expand Up @@ -1737,7 +1729,7 @@ def test_query_string_field_not_primary_is_empty(self):
expected: query successfully
"""
# 1. create a collection
collection_w, vectors = self.init_collection_general(prefix, insert_data=False, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=False, is_index=False)[0:2]

nb = 3000
df = cf.gen_default_list_data(nb)
Expand All @@ -1764,7 +1756,7 @@ def test_query_with_create_diskann_index(self):
method: create a collection and build diskann index
expected: verify query result
"""
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, is_index=False)[0:2]

collection_w.create_index(ct.default_float_vec_field_name, ct.default_diskann_index)
assert collection_w.has_index()[0]
Expand All @@ -1783,7 +1775,7 @@ def test_query_with_create_diskann_with_string_pk(self):
method: create a collection with string pk and build diskann index
expected: verify query result
"""
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, primary_field=ct.default_string_field_name, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=True, primary_field=ct.default_string_field_name, is_index=False)[0:2]
collection_w.create_index(ct.default_float_vec_field_name, ct.default_diskann_index)
assert collection_w.has_index()[0]
collection_w.load()
Expand All @@ -1802,7 +1794,7 @@ def test_query_with_scalar_field(self):
expected: query successfully
"""
# 1. create a collection
collection_w, vectors = self.init_collection_general(prefix, insert_data=False, is_index=True)[0:2]
collection_w, vectors = self.init_collection_general(prefix, insert_data=False, is_index=False)[0:2]

nb = 3000
df = cf.gen_default_list_data(nb)
Expand Down

0 comments on commit 8b7bd87

Please sign in to comment.