Skip to content

Commit

Permalink
test: add null and default test cases (milvus-io#36612)
Browse files Browse the repository at this point in the history
issue: milvus-io#36129

Signed-off-by: binbin lv <[email protected]>
  • Loading branch information
binbinlv authored Oct 8, 2024
1 parent 1fded42 commit 0d57ff0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
8 changes: 8 additions & 0 deletions tests/python_client/check/func_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ def check_describe_collection_property(res, func_name, check_items):
assert res["fields"][1]["name"] == check_items.get("vector_name", "vector")
if check_items.get("dim", None) is not None:
assert res["fields"][1]["params"]["dim"] == check_items.get("dim")
if check_items.get("nullable_fields", None) is not None:
nullable_fields = check_items.get("nullable_fields")
if not isinstance(nullable_fields, list):
log.error("nullable_fields should be a list including all the nullable fields name")
assert False
for field in res["fields"]:
if field["name"] in nullable_fields:
assert field["nullable"] is True
assert res["fields"][0]["is_primary"] is True
assert res["fields"][0]["field_id"] == 100 and (res["fields"][0]["type"] == 5 or 21)
assert res["fields"][1]["field_id"] == 101 and res["fields"][1]["type"] == 101
Expand Down
36 changes: 22 additions & 14 deletions tests/python_client/milvus_client/test_milvus_client_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,44 @@ def test_milvus_client_collection_fast_creation_all_params(self, dim, metric_typ
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.skip(reason="pymilvus issue 1864")
def test_milvus_client_collection_self_creation_default(self):
@pytest.mark.parametrize("nullable", [True, False])
def test_milvus_client_collection_self_creation_default(self, nullable):
"""
target: test fast create collection normal case
method: create collection
expected: create collection with default schema, index, and load successfully
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
dim = 128
# 1. create collection
schema = client_w.create_schema(client, enable_dynamic_field=False)[0]
schema.add_field("id_string", DataType.VARCHAR, max_length=64, is_primary=True, auto_id = False)
schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=128)
schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=dim)
schema.add_field("title", DataType.VARCHAR, max_length=64, is_partition_key=True)
schema.add_field("array_field", DataType.Array, max_capacity=12,
element_type_params={"type": DataType.VARCHAR, "max_length": 64})
index_params = client_w.prepare_index_params()
index_params.add_index("embeddings", metric_type="cosine")
index_params.add_index("title")
client_w.create_collection(client, collection_name, schema=schema, index_params=index_params)
schema.add_field("nullable_field", DataType.INT64, nullable=nullable, default_value=10)
schema.add_field("array_field", DataType.ARRAY, element_type=DataType.INT64, max_capacity=12,
max_length=64, nullable=nullable)
index_params = client_w.prepare_index_params(client)[0]
index_params.add_index("embeddings", metric_type="COSINE")
# index_params.add_index("title")
client_w.create_collection(client, collection_name, dimension=dim, schema=schema, index_params=index_params)
collections = client_w.list_collections(client)[0]
assert collection_name in collections
check_items = {"collection_name": collection_name,
"dim": dim,
"consistency_level": 0,
"enable_dynamic_field": False,
"num_partitions": 16,
"id_name": "id_string",
"vector_name": "embeddings"}
if nullable:
check_items["nullable_fields"] = ["nullable_field", "array_field"]
client_w.describe_collection(client, collection_name,
check_task=CheckTasks.check_describe_collection_property,
check_items={"collection_name": collection_name,
"dim": 128,
"consistency_level": 0})
check_items=check_items)
index = client_w.list_indexes(client, collection_name)[0]
assert index == ['vector']
# load_state = client_w.get_load_state(collection_name)[0]
assert index == ['embeddings']
if client_w.has_collection(client, collection_name)[0]:
client_w.drop_collection(client, collection_name)

Expand Down
34 changes: 33 additions & 1 deletion tests/python_client/milvus_client/test_milvus_client_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from utils.util_pymilvus import *
from common.constants import *
from pymilvus.orm.types import CONSISTENCY_STRONG, CONSISTENCY_BOUNDED, CONSISTENCY_SESSION, CONSISTENCY_EVENTUALLY
from pymilvus import DataType
from base.high_level_api_wrapper import HighLevelApiWrapper
client_w = HighLevelApiWrapper()

Expand Down Expand Up @@ -170,7 +171,7 @@ def metric_type(self, request):
******************************************************************
"""

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.tags(CaseLabel.L0)
def test_milvus_client_search_query_default(self):
"""
target: test search (high level api) normal case
Expand Down Expand Up @@ -214,6 +215,37 @@ def test_milvus_client_search_query_default(self):
client_w.release_collection(client, collection_name)
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip(reason="issue #36484")
@pytest.mark.parametrize("nullable", [True, False])
def test_milvus_client_search_query_self_creation_default(self, nullable):
"""
target: test fast create collection normal case
method: create collection
expected: create collection with default schema, index, and load successfully
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
dim = 128
# 1. create collection
schema = client_w.create_schema(client, enable_dynamic_field=False)[0]
schema.add_field(default_primary_key_field_name, DataType.VARCHAR, max_length=64, is_primary=True, auto_id = False)
schema.add_field(default_vector_field_name, DataType.FLOAT_VECTOR, dim=dim)
schema.add_field(default_string_field_name, DataType.VARCHAR, max_length=64, is_partition_key=True)
schema.add_field("nullable_field", DataType.INT64, nullable=True, default_value=10)
schema.add_field("array_field", DataType.ARRAY, element_type=DataType.INT64, max_capacity=12,
max_length=64, nullable=True)
index_params = client_w.prepare_index_params(client)[0]
index_params.add_index(default_vector_field_name, metric_type="COSINE")
client_w.create_collection(client, collection_name, dimension=dim, schema=schema, index_params=index_params)
# 2. insert
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: str(i), default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_string_field_name: str(i), "nullable_field": None, "array_field": None} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)
if client_w.has_collection(client, collection_name)[0]:
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L1)
def test_milvus_client_rename_search_query_default(self):
"""
Expand Down
22 changes: 22 additions & 0 deletions tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,28 @@ def test_collection_describe(self):
log.info(res)
assert description == res

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip(reason="issue #36596")
def test_collection_describe_nullable_default_value(self):
"""
target: test describe collection with nullable and default_value fields
method: create a collection with nullable and default_value fields, then check its information when describe
expected: return correct information
"""
collection_w = self.init_collection_general(prefix, False,
nullable_fields={ct.default_float_field_name: 0},
default_value_fields={ct.default_string_field_name: "1"})[0]
res = collection_w.describe()[0]
for field in res["fields"]:
if field["name"] == ct.default_float_field_name:
assert field["nullable"] is True
if field["name"] == ct.default_string_field_name:
if "default_value" not in field.keys():
log.error("there is no default_value key in the result of describe collection, please file a bug")
assert False
else:
assert field["default_value"] == "1"


class TestReleaseAdvanced(TestcaseBase):
@pytest.mark.tags(CaseLabel.L0)
Expand Down

0 comments on commit 0d57ff0

Please sign in to comment.