test: [cherry pick]Add json key in [] test to verify issue (#36810)

related issue: https://github.com/milvus-io/milvus/issues/36718
pr: https://github.com/milvus-io/milvus/pull/36738

Signed-off-by: yanliang567 <yanliang.qiao@zilliz.com>
This commit is contained in:
yanliang567 2024-10-12 18:03:21 +08:00 committed by GitHub
parent 523a3a0526
commit a645ab87a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 16 deletions

View File

@ -573,8 +573,10 @@ def gen_json_data_for_diff_json_types(nb=ct.default_nb, start=0, json_type="json
Method: gen json data for different json types. Refer to RFC7159
"""
if json_type == "json_embedded_object": # a json object with an embedd json object
return [{json_type: {"number": i, "level2": {"level2_number": i, "level2_float": i*1.0, "level2_str": str(i)}, "float": i*1.0}, "str": str(i)}
for i in range(start, start + nb)]
return [{json_type: {"number": i, "level2": {"level2_number": i, "level2_float": i * 1.0, "level2_str": str(i),
"level2_array": [i for i in range(i, i + 10)]},
"float": i * 1.0}, "str": str(i), "array": [i for i in range(i, i + 10)], "bool": bool(i)}
for i in range(start, start + nb)]
if json_type == "json_objects_array": # a json-objects array with 2 json objects
return [[{"number": i, "level2": {"level2_number": i, "level2_float": i*1.0, "level2_str": str(i)}, "float": i*1.0, "str": str(i)},
{"number": i, "level2": {"level2_number": i, "level2_float": i*1.0, "level2_str": str(i)}, "float": i*1.0, "str": str(i)}

View File

@ -3448,17 +3448,17 @@ class TestQueryCount(TestcaseBase):
collection_w = self.init_collection_wrap(name=c_name, schema=schema)
# 2. insert data
nb = 500
nb = 1000
for i in range(10):
data = [
cf.gen_vectors(nb, dim),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_int),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_float),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_string),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_bool),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_array),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_embedded_object),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i*nb, json_type=json_objects_array)
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_int),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_float),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_string),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_bool),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_array),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_embedded_object),
cf.gen_json_data_for_diff_json_types(nb=nb, start=i * nb, json_type=json_objects_array)
]
collection_w.insert(data)
@ -3467,15 +3467,21 @@ class TestQueryCount(TestcaseBase):
collection_w.load()
# 4. search and query with different expressions. All the expressions will return 10 results
query_exprs = [f'{json_int} < 10 ', f'{json_float} <= 200.0 and {json_float} > 190.0',
f'{json_string} in ["1","2","3","4","5","6","7","8","9","10"]',
f'{json_bool} == true and {json_float} <= 10',
f'{json_array} == [4001,4002,4003,4004,4005,4006,4007,4008,4009,4010] or {json_int} < 9',
f'{json_embedded_object}["{json_embedded_object}"]["number"] < 10',
f'{json_objects_array}[0]["level2"]["level2_str"] like "99%" and {json_objects_array}[1]["float"] > 100']
query_exprs = [
f'json_contains_any({json_embedded_object}["{json_embedded_object}"]["level2"]["level2_array"], [1,3,5,7,9])',
f'json_contains_any({json_embedded_object}["array"], [1,3,5,7,9])',
f'{json_int} < 10',
f'{json_float} <= 200.0 and {json_float} > 190.0',
f'{json_string} in ["1","2","3","4","5","6","7","8","9","10"]',
f'{json_bool} == true and {json_float} <= 10',
f'{json_array} == [4001,4002,4003,4004,4005,4006,4007,4008,4009,4010] or {json_int} < 9',
f'{json_embedded_object}["{json_embedded_object}"]["number"] < 10',
f'{json_objects_array}[0]["level2"]["level2_str"] like "199%" and {json_objects_array}[1]["float"] >= 1990'
]
search_data = cf.gen_vectors(2, dim)
search_param = {}
for expr in query_exprs:
log.debug(f"query_expr: {expr}")
collection_w.query(expr=expr, output_fields=[count],
check_task=CheckTasks.check_query_results, check_items={exp_res: [{count: 10}]})
collection_w.search(data=search_data, anns_field=ct.default_float_vec_field_name,
@ -3483,6 +3489,17 @@ class TestQueryCount(TestcaseBase):
check_task=CheckTasks.check_search_results,
check_items={"nq": 2, "limit": 10})
# verify for issue #36718
for expr in [f'{json_embedded_object}["{json_embedded_object}"]["number"] in []',
f'{json_embedded_object}["{json_embedded_object}"] in []']:
log.debug(f"query_expr: {expr}")
collection_w.query(expr=expr, output_fields=[count],
check_task=CheckTasks.check_query_results, check_items={exp_res: [{count: 0}]})
collection_w.search(data=search_data, anns_field=ct.default_float_vec_field_name,
param=search_param, limit=10, expr=expr,
check_task=CheckTasks.check_search_results,
check_items={"nq": 2, "limit": 0})
@pytest.mark.tags(CaseLabel.L2)
def test_count_with_pagination_param(self):
"""