Skip to content

Commit

Permalink
test: Add test cases about expr for null and default support (#37121)
Browse files Browse the repository at this point in the history
issue: #36129

Signed-off-by: binbin lv <[email protected]>
  • Loading branch information
binbinlv authored Oct 25, 2024
1 parent ad2df90 commit c285853
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 78 deletions.
6 changes: 3 additions & 3 deletions tests/python_client/common/common_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,15 @@ def gen_array_collection_schema(description=ct.default_desc, primary_field=ct.de
log.error("Primary key only support int or varchar")
assert False
else:
fields = [gen_int64_field(), gen_float_vec_field(dim=dim), gen_json_field(),
fields = [gen_int64_field(), gen_float_vec_field(dim=dim), gen_json_field(nullable=True),
gen_array_field(name=ct.default_int32_array_field_name, element_type=DataType.INT32,
max_capacity=max_capacity),
gen_array_field(name=ct.default_float_array_field_name, element_type=DataType.FLOAT,
max_capacity=max_capacity),
gen_array_field(name=ct.default_string_array_field_name, element_type=DataType.VARCHAR,
max_capacity=max_capacity, max_length=max_length, nullable=True)]
if with_json is False:
fields.remove(gen_json_field())
fields.remove(gen_json_field(nullable=True))

schema, _ = ApiCollectionSchemaWrapper().init_collection_schema(fields=fields, description=description,
primary_field=primary_field, auto_id=auto_id,
Expand Down Expand Up @@ -1411,7 +1411,7 @@ def gen_general_list_all_data_type(nb=ct.default_nb, dim=ct.default_dim, start=0
null_number = int(nb * nullable_fields[ct.default_bool_field_name])
null_data = [None for _ in range(null_number)]
bool_data = bool_data[:nb - null_number] + null_data
bool_values = pd.Series(data=bool_data, dtype=object)
bool_values = pd.Series(data=bool_data, dtype="bool")

float_data = [np.float32(i) for i in range(start, start + nb)]
float_values = pd.Series(data=float_data, dtype="float32")
Expand Down
21 changes: 19 additions & 2 deletions tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3144,7 +3144,6 @@ def test_collection_describe(self):
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
Expand All @@ -3163,7 +3162,7 @@ def test_collection_describe_nullable_default_value(self):
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"
assert field["default_value"].string_data == "1"


class TestReleaseAdvanced(TestcaseBase):
Expand Down Expand Up @@ -4586,6 +4585,24 @@ def test_create_collection_set_nullable_on_vector_field(self, vector_type):
error = {ct.err_code: 1100, ct.err_msg: "vector type not support null"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L1)
def test_create_collection_set_nullable_on_partition_key_field(self):
"""
target: test create collection with set nullable=True on partition key field
method: set nullable=True and is_partition_key=True on one field
expected: raise exception
"""
self._connect()
int_fields = []
c_name = cf.gen_unique_str(prefix)
# add other vector fields to maximum fields num
int_fields.append(cf.gen_int64_field(is_primary=True))
int_fields.append(cf.gen_string_field(is_partition_key=True, nullable=True))
int_fields.append(cf.gen_float_vec_field())
schema = cf.gen_collection_schema(fields=int_fields)
error = {ct.err_code: 1100, ct.err_msg: "partition key field not support nullable: invalid parameter"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)


class TestCollectionDefaultValueInvalid(TestcaseBase):
""" Test case of collection interface """
Expand Down
Loading

0 comments on commit c285853

Please sign in to comment.