From 56dbbfe4cbbb6520b126cff4f2eca0fa9b357464 Mon Sep 17 00:00:00 2001 From: dragondriver Date: Fri, 30 Apr 2021 15:56:01 +0800 Subject: [PATCH] Add simple test case to search_with_expression (#5094) Signed-off-by: dragondriver --- tests/python_test/entity/test_search.py | 45 +++++++++++++++++++++++++ tests/python_test/requirements.txt | 2 +- tests/python_test/utils.py | 7 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/python_test/entity/test_search.py b/tests/python_test/entity/test_search.py index 97782e4e15..04482acef3 100644 --- a/tests/python_test/entity/test_search.py +++ b/tests/python_test/entity/test_search.py @@ -1789,6 +1789,51 @@ class TestSearchInvalid(object): res = connect.search(collection, query) +class TestSearchWithExpression(object): + @pytest.fixture( + scope="function", + params=[1, 10, 20], + ) + def limit(self, request): + yield request.param + + @pytest.fixture( + scope="function", + params=gen_normal_expressions(), + ) + def expression(self, request): + yield request.param + + @pytest.fixture( + scope="function", + params=[ + {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": 100}}, + ] + ) + def index_param(self, request): + return request.param + + @pytest.fixture( + scope="function", + ) + def search_params(self): + return {"metric_type": "L2", "params": {"nprobe": 10}} + + @pytest.mark.tags(CaseLabel.tags_smoke) + def test_search_with_expression(self, connect, collection, index_param, search_params, limit, expression): + entities, ids = init_data(connect, collection) + assert len(ids) == default_nb + connect.create_index(collection, default_float_vec_field_name, index_param) + connect.load_collection(collection) + nq = 10 + query_data = entities[2]["values"][:nq] + res = connect.search_with_expression(collection, query_data, default_float_vec_field_name, search_params, + limit, expression) + assert len(res) == nq + for topk_results in res: + assert len(topk_results) <= limit + + def check_id_result(result, id): limit_in = 5 ids = [entity.id for entity in result] diff --git a/tests/python_test/requirements.txt b/tests/python_test/requirements.txt index 5d2662a963..c16f76319f 100644 --- a/tests/python_test/requirements.txt +++ b/tests/python_test/requirements.txt @@ -10,7 +10,7 @@ allure-pytest==2.7.0 pytest-print==0.2.1 pytest-level==0.1.1 pytest-xdist==2.2.1 -pymilvus-distributed==0.0.62 +pymilvus-distributed==0.0.63 pytest-rerunfailures==9.1.1 git+https://github.com/Projectplace/pytest-tags ndg-httpsclient diff --git a/tests/python_test/utils.py b/tests/python_test/utils.py index c82746e183..d9ed7336ae 100644 --- a/tests/python_test/utils.py +++ b/tests/python_test/utils.py @@ -867,6 +867,13 @@ def gen_binary_index(): return index_params +def gen_normal_expressions(): + expressions = [ + "int64 > 0", + ] + return expressions + + def get_search_param(index_type, metric_type="L2"): search_params = {"metric_type": metric_type} if index_type in ivf() or index_type in binary_support():