From 235969caa0ee9047c934153cc0463a78d5e2814d Mon Sep 17 00:00:00 2001 From: NicoYuan1986 <109071306+NicoYuan1986@users.noreply.github.com> Date: Mon, 29 Aug 2022 09:52:59 +0800 Subject: [PATCH] Add search cases of expressions that linking and comparing two fields (#18857) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “nico” Signed-off-by: “nico” --- tests/python_client/common/common_func.py | 14 ++++++++ tests/python_client/testcases/test_search.py | 36 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/python_client/common/common_func.py b/tests/python_client/common/common_func.py index f04d0d365f..af486ba170 100644 --- a/tests/python_client/common/common_func.py +++ b/tests/python_client/common/common_func.py @@ -494,6 +494,20 @@ def gen_normal_expressions(): ] return expressions +def gen_field_compare_expressions(): + expressions = [ + "int64_1 | int64_2 == 1", + "int64_1 && int64_2 ==1", + "int64_1 + int64_2 == 10", + "int64_1 - int64_2 == 2", + "int64_1 * int64_2 == 8", + "int64_1 / int64_2 == 2", + "int64_1 ** int64_2 == 4", + "int64_1 % int64_2 == 0", + "int64_1 in int64_2", + "int64_1 + int64_2 >= 10" + ] + return expressions def gen_normal_string_expressions(field): expressions = [ diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index 88ecb69a56..49e74ee729 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -3,6 +3,7 @@ import numbers import random import pytest +import pandas as pd from time import sleep from base.client_base import TestcaseBase @@ -389,6 +390,40 @@ class TestCollectionSearchInvalid(TestcaseBase): "err_msg": "The type of expr must be string ," "but {} is given".format(type(invalid_search_expr))}) + @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.parametrize("expression", cf.gen_field_compare_expressions()) + def test_search_with_expression_join_two_fields(self, expression): + """ + target: test search with expressions linking two fields such as 'and' + method: create a collection and search with different conjunction + expected: raise exception and report the error + """ + # 1. create a collection + nb = 1000 + dim = 1 + fields = [cf.gen_int64_field("int64_1"), cf.gen_int64_field("int64_2"), + cf.gen_float_vec_field(dim=dim)] + schema = cf.gen_collection_schema(fields=fields, primary_field="int64_1") + collection_w = self.init_collection_wrap(schema=schema) + + # 2. insert data + values = pd.Series(data=[i for i in range(0, nb)]) + dataframe = pd.DataFrame({"int64_1": values, "int64_2": values, + ct.default_float_vec_field_name: cf.gen_vectors(nb, dim)}) + collection_w.insert(dataframe) + + # 3. search with expression + log.info("test_search_with_expression: searching with expression: %s" % expression) + collection_w.load() + expression = expression.replace("&&", "and").replace("||", "or") + vectors = [[random.random() for _ in range(dim)] for _ in range(default_nq)] + collection_w.search(vectors[:default_nq], default_search_field, + default_search_params, nb, expression, + check_task=CheckTasks.err_res, + check_items={"err_code": 1, + "err_msg": "failed to create query plan: " + "cannot parse expression: %s" % expression}) + @pytest.mark.tags(CaseLabel.L2) def test_search_param_invalid_expr_value(self, get_invalid_expr_value): """ @@ -2519,6 +2554,7 @@ class TestCollectionSearch(TestcaseBase): "limit": nb_old + nb_new, "_async": _async}) + class TestSearchBase(TestcaseBase): @pytest.fixture( scope="function",