update pymilvus version and add cases of array exists (#28197)

Signed-off-by: nico <cheng.yuan@zilliz.com>
pull/28211/head
nico 2023-11-07 10:14:19 +08:00 committed by GitHub
parent c41df18b6d
commit 945c89f779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 2 deletions

View File

@ -395,7 +395,7 @@ def gen_default_data_for_upsert(nb=ct.default_nb, dim=ct.default_dim, start=0, s
return df, float_values
def gen_array_dataframe_data(nb=ct.default_nb, dim=ct.default_dim, start=0,
def gen_array_dataframe_data(nb=ct.default_nb, dim=ct.default_dim, start=0, auto_id=False,
array_length=ct.default_max_capacity, with_json=False, random_primary_key=False):
if not random_primary_key:
int_values = pd.Series(data=[i for i in range(start, start + nb)])
@ -418,6 +418,8 @@ def gen_array_dataframe_data(nb=ct.default_nb, dim=ct.default_dim, start=0,
})
if with_json is False:
df.drop(ct.default_json_field_name, axis=1, inplace=True)
if auto_id:
df.drop(ct.default_int64_field_name, axis=1, inplace=True)
return df

View File

@ -12,7 +12,7 @@ allure-pytest==2.7.0
pytest-print==0.2.1
pytest-level==0.1.1
pytest-xdist==2.5.0
pymilvus==2.3.2.post1.dev1
pymilvus==2.3.2.post1.dev4
pytest-rerunfailures==9.1.1
git+https://github.com/Projectplace/pytest-tags
ndg-httpsclient

View File

@ -3126,6 +3126,53 @@ class TestCollectionSearch(TestcaseBase):
ids = hits.ids
assert set(ids) == set(filter_ids)
@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("exists", ["exists"])
@pytest.mark.parametrize("json_field_name", ["json_field", "json_field['number']", "json_field['name']",
"float_array", "not_exist_field", "new_added_field"])
def test_search_with_expression_exists(self, exists, json_field_name, _async, enable_dynamic_field):
"""
target: test search with different expressions
method: test search with different expressions
expected: searched successfully with correct limit(topK)
"""
if not enable_dynamic_field:
pytest.skip("not allowed")
# 1. initialize with data
nb = 100
schema = cf.gen_array_collection_schema(with_json=True, enable_dynamic_field=enable_dynamic_field)
collection_w = self.init_collection_wrap(schema=schema, enable_dynamic_field=enable_dynamic_field)
log.info(schema.fields)
if enable_dynamic_field:
data = cf.get_row_data_by_schema(nb, schema=schema)
for i in range(nb):
data[i]["new_added_field"] = i
log.info(data[0])
else:
data = cf.gen_array_dataframe_data(nb, with_json=True)
log.info(data.head(1))
collection_w.insert(data)
# 2. create index
index_param = {"index_type": "FLAT", "metric_type": "COSINE", "params": {}}
collection_w.create_index("float_vector", index_param)
collection_w.load()
# 3. search with expression
expression = exists + " " + json_field_name
if enable_dynamic_field:
limit = nb if json_field_name in data[0].keys() else 0
else:
limit = nb if json_field_name in data.columns.to_list() else 0
log.info("test_search_with_expression: searching with expression: %s" % expression)
search_res, _ = collection_w.search(vectors[:default_nq], default_search_field,
default_search_params, nb, expression,
_async=_async,
check_task=CheckTasks.check_search_results,
check_items={"nq": default_nq,
"limit": limit,
"_async": _async})
@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.xfail(reason="issue 24514")
@pytest.mark.parametrize("expression", cf.gen_normal_expressions_field(default_float_field_name))
@ -3406,6 +3453,39 @@ class TestCollectionSearch(TestcaseBase):
"_async": _async,
"output_fields": output_fields})
@pytest.mark.tags(CaseLabel.L2)
def test_search_output_array_field(self, auto_id, enable_dynamic_field):
"""
target: test search output array field
method: create connection, collection, insert and search
expected: search successfully
"""
# 1. create a collection
schema = cf.gen_array_collection_schema(auto_id=auto_id)
collection_w = self.init_collection_wrap(schema=schema)
# 2. insert data
if enable_dynamic_field:
data = cf.get_row_data_by_schema(schema=schema)
else:
data = cf.gen_array_dataframe_data(auto_id=auto_id)
collection_w.insert(data)
# 3. create index and load
collection_w.create_index(default_search_field)
collection_w.load()
# 4. search output array field, check
output_fields = [ct.default_int64_field_name, ct.default_int32_array_field_name,
ct.default_float_array_field_name]
collection_w.search(vectors[:default_nq], default_search_field, {}, default_limit,
output_fields=output_fields,
check_task=CheckTasks.check_search_results,
check_items={"nq": default_nq,
"limit": default_limit,
"output_fields": output_fields})
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("index, params",
zip(ct.all_index_types[:7],