From 84b3c7ea60523a0c0b1ebcae16fb86151fcb9b48 Mon Sep 17 00:00:00 2001 From: jingkl <34296482+jingkl@users.noreply.github.com> Date: Wed, 21 Sep 2022 10:14:51 +0800 Subject: [PATCH] Add the string testcase (#19287) Signed-off-by: jingkl Signed-off-by: jingkl --- tests/python_client/testcases/test_delete.py | 33 ++++++++ tests/python_client/testcases/test_index.py | 22 +++++ tests/python_client/testcases/test_insert.py | 33 ++++++++ tests/python_client/testcases/test_query.py | 62 ++++++++++++++ tests/python_client/testcases/test_search.py | 85 ++++++++++++++++++++ 5 files changed, 235 insertions(+) diff --git a/tests/python_client/testcases/test_delete.py b/tests/python_client/testcases/test_delete.py index e999b760e3..f249cc112a 100644 --- a/tests/python_client/testcases/test_delete.py +++ b/tests/python_client/testcases/test_delete.py @@ -1745,3 +1745,36 @@ class TestDeleteString(TestcaseBase): check_task=CheckTasks.check_query_results, check_items={'exp_res': res, 'primary_field': ct.default_string_field_name, 'with_vec': True}) collection_w.search(data=[df_new[ct.default_float_vec_field_name][0]], anns_field=ct.default_float_vec_field_name, param=default_search_params, limit=1) + + @pytest.mark.tags(CaseLabel.L1) + def test_delete_with_string_field_is_empty(self): + """ + target: test delete with string field is empty + method: 1.string field is PK, insert empty data + 2.delete ids from collection + 3.load and query with id + expected: No query result + """ + # create collection, insert data without flush + schema = cf.gen_string_pk_default_collection_schema() + collection_w = self.init_collection_wrap(name=cf.gen_unique_str(prefix), schema=schema) + + nb = 3000 + df = cf.gen_default_list_data(nb) + df[2] = [""for _ in range(nb)] + + collection_w.insert(df) + collection_w.load() + assert collection_w.num_entities == nb + + # delete + string_expr = "varchar in [\"\", \"\"]" + del_res, _ = collection_w.delete(string_expr) + assert del_res.delete_count == 2 + + # load and query with id + collection_w.load() + collection_w.query(string_expr, check_task=CheckTasks.check_query_empty) + + + diff --git a/tests/python_client/testcases/test_index.py b/tests/python_client/testcases/test_index.py index 12ea10aaca..01973910ff 100644 --- a/tests/python_client/testcases/test_index.py +++ b/tests/python_client/testcases/test_index.py @@ -1443,3 +1443,25 @@ class TestIndexString(TestcaseBase): collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2) collection_w.drop_index(index_name=index_name2) assert len(collection_w.indexes) == 0 + + @pytest.mark.tags(CaseLabel.L1) + def test_index_with_string_field_empty(self): + """ + target: test drop index with string field + method: 1.create collection and insert data + 2.create index and uses collection.drop_index () drop index + expected: drop index successfully + """ + c_name = cf.gen_unique_str(prefix) + collection_w = self.init_collection_wrap(name=c_name) + + nb = 3000 + data = cf.gen_default_list_data(nb) + data[2] = [""for _ in range(nb)] + collection_w.insert(data=data) + + collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2) + assert collection_w.has_index(index_name=index_name2)[0] == True + + collection_w.drop_index(index_name=index_name2) + assert len(collection_w.indexes) == 0 \ No newline at end of file diff --git a/tests/python_client/testcases/test_insert.py b/tests/python_client/testcases/test_insert.py index e5b171f6ef..f2967745e4 100644 --- a/tests/python_client/testcases/test_insert.py +++ b/tests/python_client/testcases/test_insert.py @@ -1217,3 +1217,36 @@ class TestInsertString(TestcaseBase): data[2] = [" "for _ in range(nb)] collection_w.insert(data) assert collection_w.num_entities == nb + + @pytest.mark.tags(CaseLabel.L1) + def test_insert_string_field_empty(self): + """ + target: test create collection with string field + method: 1.create a collection + 2.Insert string field with empty + expected: Insert successfully + """ + c_name = cf.gen_unique_str(prefix) + collection_w = self.init_collection_wrap(name=c_name) + nb = 1000 + data = cf.gen_default_list_data(nb) + data[2] = [""for _ in range(nb)] + collection_w.insert(data) + assert collection_w.num_entities == nb + + @pytest.mark.tags(CaseLabel.L1) + def test_insert_string_field_is_pk_and_empty(self): + """ + target: test create collection with string field is primary + method: 1.create a collection + 2.Insert string field with empty, string field is pk + expected: Insert successfully + """ + c_name = cf.gen_unique_str(prefix) + schema = cf.gen_string_pk_default_collection_schema() + collection_w = self.init_collection_wrap(name=c_name, schema=schema) + nb = 1000 + data = cf.gen_default_list_data(nb) + data[2] = [""for _ in range(nb)] + collection_w.insert(data) + assert collection_w.num_entities == nb diff --git a/tests/python_client/testcases/test_query.py b/tests/python_client/testcases/test_query.py index 0ba5ccc60f..06e4a47f8a 100644 --- a/tests/python_client/testcases/test_query.py +++ b/tests/python_client/testcases/test_query.py @@ -1384,3 +1384,65 @@ class TestqueryString(TestcaseBase): check_items={exp_res: df_dict_list, "primary_field": default_int_field_name, "with_vec": True}) + + @pytest.mark.tags(CaseLabel.L2) + def test_query_string_field_pk_is_empty(self): + """ + target: test query with string expr and string field is primary + method: create collection , string field is primary + collection load and insert empty data with string field + collection query uses string expr in string field + expected: query successfully + """ + # 1. create a collection + schema = cf.gen_string_pk_default_collection_schema() + collection_w = self.init_collection_wrap(cf.gen_unique_str(prefix), schema=schema) + + collection_w.load() + + nb = 3000 + df = cf.gen_default_list_data(nb) + df[2] = [""for _ in range(nb)] + + collection_w.insert(df) + assert collection_w.num_entities == nb + + + string_exp = "varchar >= \"\"" + output_fields = [default_int_field_name, default_float_field_name, default_string_field_name] + res, _ = collection_w.query(string_exp, output_fields=output_fields) + + assert len(res) == 1 + + + @pytest.mark.tags(CaseLabel.L2) + def test_query_string_field_not_primary_is_empty(self): + """ + target: test query with string expr and string field is not primary + method: create collection , string field is primary + collection load and insert empty data with string field + collection query uses string expr in string field + expected: query successfully + """ + # 1. create a collection + collection_w, vectors = self.init_collection_general(prefix, insert_data=False)[0:2] + + nb = 3000 + df = cf.gen_default_list_data(nb) + df[2] = [""for _ in range(nb)] + + collection_w.insert(df) + assert collection_w.num_entities == nb + collection_w.load() + + collection_w.create_index(ct.default_float_vec_field_name, default_index_params) + assert collection_w.has_index()[0] + + + output_fields = [default_int_field_name, default_float_field_name, default_string_field_name] + + expr = "varchar == \"\"" + res, _ = collection_w.query(expr, output_fields=output_fields) + + assert len(res) == nb + diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index a68570aa16..8c5e3b7006 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -3550,3 +3550,88 @@ class TestsearchString(TestcaseBase): "limit": default_limit, "_async": _async} ) + + @pytest.mark.tags(CaseLabel.L2) + def test_search_string_field_is_primary_insert_empty(self, _async): + """ + target: test search with string expr and string field is primary + method: create collection ,string field is primary + collection load and insert data + collection search uses string expr in string field + expected: Search successfully + """ + # 1. initialize with data + collection_w, _, _, _ = \ + self.init_collection_general(prefix, False, primary_field=ct.default_string_field_name)[0:4] + + nb = 3000 + data = cf.gen_default_list_data(nb) + data[2] = [""for _ in range(nb)] + collection_w.insert(data=data) + + collection_w.load() + + + search_string_exp = "varchar >= \"\"" + limit =1 + + # 2. search + log.info("test_search_string_field_is_primary_true: searching collection %s" % collection_w.name) + vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)] + output_fields = [default_string_field_name, default_float_field_name] + collection_w.search(vectors[:default_nq], default_search_field, + default_search_params, limit, + search_string_exp, + output_fields=output_fields, + _async=_async, + travel_timestamp=0, + check_task=CheckTasks.check_search_results, + check_items={"nq": default_nq, + "limit": limit, + "_async": _async}) + + + @pytest.mark.tags(CaseLabel.L2) + def test_search_string_field_not_primary_is_empty(self, _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, False, primary_field=ct.default_int64_field_name)[0:4] + + nb = 3000 + data = cf.gen_default_list_data(nb) + data[2] = [""for _ in range(nb)] + + collection_w.insert(data) + assert collection_w.num_entities == nb + + # 2. create index + index_param = {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": 100}} + collection_w.create_index("float_vector", index_param) + collection_w.load() + + + search_string_exp = "varchar >= \"\"" + + # 3. 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_string_field_name, default_float_field_name] + collection_w.search(vectors[:default_nq], default_search_field, + default_search_params, default_limit, + search_string_exp, + output_fields=output_fields, + _async=_async, + travel_timestamp=0, + check_task=CheckTasks.check_search_results, + check_items={"nq": default_nq, + "ids": insert_ids, + "limit": default_limit, + "_async": _async}) +