diff --git a/tests/python_client/testcases/test_query.py b/tests/python_client/testcases/test_query.py index 2edfc18413..3d59e84ce2 100644 --- a/tests/python_client/testcases/test_query.py +++ b/tests/python_client/testcases/test_query.py @@ -1275,4 +1275,16 @@ class TestqueryString(TestcaseBase): res, _ = collection_w.query(default_string_term_expr, output_fields=[ct.default_binary_vec_field_name]) assert len(res) == 2 - + @pytest.mark.tags(CaseLabel.L1) + def test_query_string_expr_with_prefixes(self): + """ + target: test query with + method: specify string primary field as output field + expected: return string primary field + """ + collection_w, vectors = self.init_collection_general(prefix, insert_data=True, primary_field=ct.default_string_field_name)[0:2] + res = vectors[0].iloc[:1, :3].to_dict('records') + expression = "varchar startsWith \"0\"" + output_fields = [default_int_field_name, default_float_field_name, default_string_field_name] + collection_w.query(expression, output_fields=output_fields, + check_task=CheckTasks.check_query_results, check_items={exp_res: res}) diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index 4836f2f299..e948814bc3 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -27,6 +27,7 @@ default_search_exp = "int64 >= 0" default_search_string_exp = "varchar >= \"0\"" default_search_mix_exp = "int64 >= 0 && varchar >= \"0\"" default_invaild_string_exp = "varchar >= 0" +perfix_expr = "varchar startsWith \"0\"" default_search_field = ct.default_float_vec_field_name default_search_params = ct.default_search_params default_int64_field_name = ct.default_int64_field_name @@ -2987,3 +2988,37 @@ class TestsearchString(TestcaseBase): "ids": insert_ids, "limit": default_limit, "_async": _async}) + + @pytest.mark.tags(CaseLabel.L2) + def test_search_string_field_not_primary_perfix(self, auto_id, _async): + """ + target: test search with string expr and string field is not primary + method: create collection and insert data + create index and collection load + collection search uses string expr in string field, string field is not primary + expected: Search successfully + """ + # 1. initialize with data + collection_w, _, _, insert_ids = \ + self.init_collection_general(prefix, True, auto_id=auto_id, dim=default_dim)[0:4] + index_param = {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": 100}} + collection_w.create_index("float_vector", index_param, index_name="a") + index_param_two ={} + collection_w.create_index("varchar", index_param_two, index_name="b") + collection_w.load() + # 2. search + log.info("test_search_string_field_not_primary: searching collection %s" % collection_w.name) + vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)] + output_fields = [default_float_field_name, default_string_field_name] + collection_w.search(vectors[:default_nq], default_search_field, + default_search_params, default_limit, + perfix_expr, + output_fields=output_fields, + _async=_async, + travel_timestamp=0, + check_task=CheckTasks.check_search_results, + check_items={"nq": default_nq, + "ids": insert_ids, + "limit": 1, + "_async": _async} + ) \ No newline at end of file