From 945c89f779d08c8e0dd80496fbcb5f23ccdd1cc8 Mon Sep 17 00:00:00 2001 From: nico <109071306+NicoYuan1986@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:14:19 +0800 Subject: [PATCH] update pymilvus version and add cases of array exists (#28197) Signed-off-by: nico --- tests/python_client/common/common_func.py | 4 +- tests/python_client/requirements.txt | 2 +- tests/python_client/testcases/test_search.py | 80 ++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/tests/python_client/common/common_func.py b/tests/python_client/common/common_func.py index 23dc77a89c..eef0815f8f 100644 --- a/tests/python_client/common/common_func.py +++ b/tests/python_client/common/common_func.py @@ -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 diff --git a/tests/python_client/requirements.txt b/tests/python_client/requirements.txt index 68e3370879..9a795078ba 100644 --- a/tests/python_client/requirements.txt +++ b/tests/python_client/requirements.txt @@ -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 diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index 4806bcd49d..083833c9c5 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -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],