mirror of https://github.com/milvus-io/milvus.git
Enable query test cases in tests/ (#6089)
* Enable query test cases in tests/ Signed-off-by: zw <zw@milvus.io> * update Signed-off-by: zw <zw@milvus.io> Co-authored-by: zw <zw@milvus.io>pull/6092/head
parent
e87372761a
commit
5d7eeddeb9
|
@ -316,7 +316,7 @@ class TestInsertBase:
|
||||||
logging.getLogger().info(len(ids))
|
logging.getLogger().info(len(ids))
|
||||||
entity = copy.deepcopy(default_entity)
|
entity = copy.deepcopy(default_entity)
|
||||||
entity[0]["values"] = ids
|
entity[0]["values"] = ids
|
||||||
with pytest.raises(BaseException) as e:
|
with pytest.raises(Exception) as e:
|
||||||
connect.insert(id_collection, entity)
|
connect.insert(id_collection, entity)
|
||||||
|
|
||||||
@pytest.mark.timeout(ADD_TIMEOUT)
|
@pytest.mark.timeout(ADD_TIMEOUT)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import pdb
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -9,7 +10,8 @@ default_entities = ut.gen_entities(ut.default_nb, is_normal=True)
|
||||||
raw_vectors, default_binary_entities = ut.gen_binary_entities(ut.default_nb)
|
raw_vectors, default_binary_entities = ut.gen_binary_entities(ut.default_nb)
|
||||||
default_int_field_name = "int64"
|
default_int_field_name = "int64"
|
||||||
default_float_field_name = "float"
|
default_float_field_name = "float"
|
||||||
default_term_expr = f'{default_int_field_name} in [0, 1]'
|
default_pos = 5
|
||||||
|
default_term_expr = f'{default_int_field_name} in {[i for i in range(default_pos)]}'
|
||||||
|
|
||||||
|
|
||||||
def init_data(connect, collection, nb=ut.default_nb, partition_names=None, auto_id=True):
|
def init_data(connect, collection, nb=ut.default_nb, partition_names=None, auto_id=True):
|
||||||
|
@ -56,7 +58,6 @@ def init_binary_data(connect, collection, nb=3000, insert=True, partition_names=
|
||||||
return insert_raw_vectors, insert_entities, ids
|
return insert_raw_vectors, insert_entities, ids
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="waiting for collection update")
|
|
||||||
class TestQueryBase:
|
class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
test Query interface
|
test Query interface
|
||||||
|
@ -77,7 +78,7 @@ class TestQueryBase:
|
||||||
def get_simple_index(self, request, connect):
|
def get_simple_index(self, request, connect):
|
||||||
return request.param
|
return request.param
|
||||||
|
|
||||||
def test_query(self, connect, collection):
|
def test_query_invalid(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query
|
target: test query
|
||||||
method: query with term expr
|
method: query with term expr
|
||||||
|
@ -85,11 +86,27 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
pos = 5
|
|
||||||
connect.load_collection(collection)
|
connect.load_collection(collection)
|
||||||
term_expr = f'{default_int_field_name} in {entities[:pos]}'
|
term_expr = f'{default_int_field_name} in {entities[:default_pos]}'
|
||||||
|
with pytest.raises(Exception):
|
||||||
res = connect.query(collection, term_expr)
|
res = connect.query(collection, term_expr)
|
||||||
logging.getLogger().debug(res)
|
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
|
def test_query_valid(self, connect, collection):
|
||||||
|
"""
|
||||||
|
target: test query
|
||||||
|
method: query with term expr
|
||||||
|
expected: verify query result
|
||||||
|
"""
|
||||||
|
entities, ids = init_data(connect, collection)
|
||||||
|
assert len(ids) == ut.default_nb
|
||||||
|
connect.load_collection(collection)
|
||||||
|
term_expr = f'{default_int_field_name} in {ids[:default_pos]}'
|
||||||
|
res = connect.query(collection, term_expr)
|
||||||
|
assert len(res) == default_pos
|
||||||
|
for i in range(default_pos):
|
||||||
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
|
ut.assert_equal_vector(res[i][ut.default_float_vec_field_name], entities[-1]["values"][i])
|
||||||
|
|
||||||
def test_query_collection_not_existed(self, connect):
|
def test_query_collection_not_existed(self, connect):
|
||||||
"""
|
"""
|
||||||
|
@ -97,7 +114,7 @@ class TestQueryBase:
|
||||||
method: query not existed collection
|
method: query not existed collection
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
ex_msg = 'can not found collection'
|
ex_msg = 'find collection'
|
||||||
collection = "not_exist"
|
collection = "not_exist"
|
||||||
with pytest.raises(Exception, match=ex_msg):
|
with pytest.raises(Exception, match=ex_msg):
|
||||||
connect.query(collection, default_term_expr)
|
connect.query(collection, default_term_expr)
|
||||||
|
@ -108,7 +125,7 @@ class TestQueryBase:
|
||||||
method: close connect and query
|
method: close connect and query
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
ex_msg = 'todo'
|
ex_msg = 'NoneType'
|
||||||
with pytest.raises(Exception, match=ex_msg):
|
with pytest.raises(Exception, match=ex_msg):
|
||||||
dis_connect.query(collection, default_term_expr)
|
dis_connect.query(collection, default_term_expr)
|
||||||
|
|
||||||
|
@ -119,10 +136,10 @@ class TestQueryBase:
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
collection_name = get_collection_name
|
collection_name = get_collection_name
|
||||||
msg = 'invalid collection name'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection_name, default_term_expr)
|
connect.query(collection_name, default_term_expr)
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6035")
|
||||||
def test_query_after_index(self, connect, collection, get_simple_index):
|
def test_query_after_index(self, connect, collection, get_simple_index):
|
||||||
"""
|
"""
|
||||||
target: test query after creating index
|
target: test query after creating index
|
||||||
|
@ -133,9 +150,15 @@ class TestQueryBase:
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.create_index(collection, ut.default_float_vec_field_name, get_simple_index)
|
connect.create_index(collection, ut.default_float_vec_field_name, get_simple_index)
|
||||||
connect.load_collection(collection)
|
connect.load_collection(collection)
|
||||||
res = connect.query(collection, default_term_expr)
|
term_expr = f'{default_int_field_name} in {ids[:default_pos]}'
|
||||||
|
res = connect.query(collection, term_expr)
|
||||||
logging.getLogger().info(res)
|
logging.getLogger().info(res)
|
||||||
|
assert len(res) == default_pos
|
||||||
|
for i in range(default_pos):
|
||||||
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
|
ut.assert_equal_vector(res[i][ut.default_float_vec_field_name], entities[-1]["values"][i])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
def test_query_after_search(self, connect, collection):
|
def test_query_after_search(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query after search
|
target: test query after search
|
||||||
|
@ -151,9 +174,15 @@ class TestQueryBase:
|
||||||
search_res = connect.search(collection, query)
|
search_res = connect.search(collection, query)
|
||||||
assert len(search_res) == nq
|
assert len(search_res) == nq
|
||||||
assert len(search_res[0]) == top_k
|
assert len(search_res[0]) == top_k
|
||||||
query_res = connect.query(collection, default_term_expr)
|
term_expr = f'{default_int_field_name} in {ids[:default_pos]}'
|
||||||
logging.getLogger().info(query_res)
|
res = connect.query(collection, term_expr)
|
||||||
|
logging.getLogger().info(res)
|
||||||
|
assert len(res) == default_pos
|
||||||
|
for i in range(default_pos):
|
||||||
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
|
ut.assert_equal_vector(res[i][ut.default_float_vec_field_name], entities[-1]["values"][i])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6053")
|
||||||
def test_query_empty_collection(self, connect, collection):
|
def test_query_empty_collection(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query empty collection
|
target: test query empty collection
|
||||||
|
@ -163,6 +192,7 @@ class TestQueryBase:
|
||||||
connect.load_collection(collection)
|
connect.load_collection(collection)
|
||||||
res = connect.query(collection, default_term_expr)
|
res = connect.query(collection, default_term_expr)
|
||||||
logging.getLogger().info(res)
|
logging.getLogger().info(res)
|
||||||
|
assert len(res) == 0
|
||||||
|
|
||||||
def test_query_without_loading(self, connect, collection):
|
def test_query_without_loading(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -172,17 +202,21 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
msg = 'can not find collection'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr)
|
connect.query(collection, default_term_expr)
|
||||||
|
|
||||||
def test_query_auto_id_collection(self, connect, id_collection):
|
def test_query_collection_not_primary_key(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query on collection that primary field auto_id=True
|
target: test query on collection that not on the primary field
|
||||||
method: 1.create collection with auto_id=True 2.query on primary field
|
method: 1.create collection with auto_id=True 2.query on the other field
|
||||||
expected: todo
|
expected: exception raised
|
||||||
"""
|
"""
|
||||||
pass
|
entities, ids = init_data(connect, collection)
|
||||||
|
assert len(ids) == ut.default_nb
|
||||||
|
connect.load_collection(collection)
|
||||||
|
term_expr = f'{default_float_field_name} in {entities[:default_pos]}'
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
connect.query(collection, term_expr)
|
||||||
|
|
||||||
def test_query_expr_none(self, connect, collection):
|
def test_query_expr_none(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -192,51 +226,23 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
msg = 'invalid expr'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, None)
|
connect.query(collection, None)
|
||||||
|
|
||||||
@pytest.mark.parametrize("expr", [1, 2., [], {}, ()])
|
@pytest.mark.parametrize("expr", [1, "1", "12-s", "中文", [], {}, ()])
|
||||||
def test_query_expr_non_string(self, connect, collection, expr):
|
def test_query_expr_invalid_string(self, connect, collection, expr):
|
||||||
"""
|
"""
|
||||||
target: test query with non-string expr
|
target: test query with non-string expr
|
||||||
method: query with non-string expr, eg 1, [] ..
|
method: query with non-string expr, eg 1, [] ..
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
# entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
# assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
msg = 'invalid expr'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
@pytest.mark.parametrize("expr", ["12-s", "中文", "a", " "])
|
|
||||||
def test_query_expr_invalid_string(self, connect, collection, expr):
|
|
||||||
"""
|
|
||||||
target: test query with invalid expr
|
|
||||||
method: query with invalid string expr
|
|
||||||
expected: raise exception
|
|
||||||
"""
|
|
||||||
entities, ids = init_data(connect, collection)
|
|
||||||
assert len(ids) == ut.default_nb
|
|
||||||
connect.flush(collection)
|
|
||||||
msg = 'invalid expr'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
|
||||||
|
|
||||||
def test_query_expr_term(self, connect, collection):
|
|
||||||
"""
|
|
||||||
target: test query with TermExpr
|
|
||||||
method: query with TermExpr
|
|
||||||
expected: query result is correct
|
|
||||||
"""
|
|
||||||
entities, ids = init_data(connect, collection)
|
|
||||||
assert len(ids) == ut.default_nb
|
|
||||||
connect.flush(collection)
|
|
||||||
res = connect.query(collection, default_term_expr)
|
|
||||||
logging.getLogger().info(res)
|
|
||||||
|
|
||||||
def test_query_expr_not_existed_field(self, connect, collection):
|
def test_query_expr_not_existed_field(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query with not existed field
|
target: test query with not existed field
|
||||||
|
@ -245,42 +251,9 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
term_expr = 'field in [1, 2]'
|
term_expr = 'field in [1, 2]'
|
||||||
msg = 'field not existed'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, term_expr)
|
|
||||||
|
|
||||||
def test_query_expr_unsupported_field(self, connect, collection):
|
|
||||||
"""
|
|
||||||
target: test query on unsupported field
|
|
||||||
method: query on float field
|
|
||||||
expected: raise exception
|
|
||||||
"""
|
|
||||||
entities, ids = init_data(connect, collection)
|
|
||||||
assert len(ids) == ut.default_nb
|
|
||||||
connect.flush(collection)
|
|
||||||
term_expr = f'{default_float_field_name} in [1., 2.]'
|
|
||||||
msg = 'only supported on int field'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, term_expr)
|
|
||||||
|
|
||||||
def test_query_expr_non_primary_field(self, connect, collection):
|
|
||||||
"""
|
|
||||||
target: test query on non-primary field
|
|
||||||
method: query on non-primary int field
|
|
||||||
expected: raise exception
|
|
||||||
"""
|
|
||||||
field_name = "int2"
|
|
||||||
fields = ut.add_field_default(field_name=field_name)
|
|
||||||
c_name = ut.gen_unique_str()
|
|
||||||
connect.create_collection(c_name, fields)
|
|
||||||
entities = ut.add_field(field_name=field_name)
|
|
||||||
connect.insert(collection, entities)
|
|
||||||
connect.flush(c_name)
|
|
||||||
term_expr = f'{field_name} in [1, 2]'
|
|
||||||
msg = 'only supported on primary field'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, term_expr)
|
connect.query(collection, term_expr)
|
||||||
|
|
||||||
@pytest.mark.parametrize("expr", [f'{default_int_field_name} inn [1, 2]',
|
@pytest.mark.parametrize("expr", [f'{default_int_field_name} inn [1, 2]',
|
||||||
|
@ -292,11 +265,8 @@ class TestQueryBase:
|
||||||
method: query with wrong keyword term expr
|
method: query with wrong keyword term expr
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
connect.load_collection(collection)
|
||||||
assert len(ids) == ut.default_nb
|
with pytest.raises(Exception):
|
||||||
connect.flush(collection)
|
|
||||||
msg = 'invalid expr'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
@pytest.mark.parametrize("expr", [f'{default_int_field_name} in 1',
|
@pytest.mark.parametrize("expr", [f'{default_int_field_name} in 1',
|
||||||
|
@ -308,11 +278,8 @@ class TestQueryBase:
|
||||||
method: query with non-array term expr
|
method: query with non-array term expr
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
connect.load_collection(collection)
|
||||||
assert len(ids) == ut.default_nb
|
with pytest.raises(Exception):
|
||||||
connect.flush(collection)
|
|
||||||
msg = 'invalid expr'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
def test_query_expr_empty_term_array(self, connect, collection):
|
def test_query_expr_empty_term_array(self, connect, collection):
|
||||||
|
@ -323,7 +290,7 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
term_expr = f'{default_int_field_name} in []'
|
term_expr = f'{default_int_field_name} in []'
|
||||||
res = connect.query(collection, term_expr)
|
res = connect.query(collection, term_expr)
|
||||||
assert len(res) == 0
|
assert len(res) == 0
|
||||||
|
@ -336,14 +303,15 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
term_expr = f'{default_int_field_name} in [0]'
|
term_expr = f'{default_int_field_name} in [0]'
|
||||||
res = connect.query(collection, term_expr)
|
res = connect.query(collection, term_expr)
|
||||||
assert len(res) == 1
|
assert len(res) == 1
|
||||||
assert res[0][default_int_field_name] == entities[0]["values"][0]
|
assert res[0][default_int_field_name] == entities[0]["values"][0]
|
||||||
assert res[1][default_float_field_name] == entities[1]["values"][0]
|
assert res[0][default_float_field_name] == entities[1]["values"][0]
|
||||||
assert res[2][ut.default_float_vec_field_name] == entities[2]["values"][0]
|
ut.assert_equal_vector(res[0][ut.default_float_vec_field_name], entities[2]["values"][0])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6072")
|
||||||
def test_query_binary_expr_single_term_array(self, connect, binary_collection):
|
def test_query_binary_expr_single_term_array(self, connect, binary_collection):
|
||||||
"""
|
"""
|
||||||
target: test query with single array term expr
|
target: test query with single array term expr
|
||||||
|
@ -352,7 +320,7 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
_, binary_entities, ids = init_binary_data(connect, binary_collection)
|
_, binary_entities, ids = init_binary_data(connect, binary_collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(binary_collection)
|
connect.load_collection(binary_collection)
|
||||||
term_expr = f'{default_int_field_name} in [0]'
|
term_expr = f'{default_int_field_name} in [0]'
|
||||||
res = connect.query(binary_collection, term_expr)
|
res = connect.query(binary_collection, term_expr)
|
||||||
assert len(res) == 1
|
assert len(res) == 1
|
||||||
|
@ -360,6 +328,8 @@ class TestQueryBase:
|
||||||
assert res[1][default_float_field_name] == binary_entities[1]["values"][0]
|
assert res[1][default_float_field_name] == binary_entities[1]["values"][0]
|
||||||
assert res[2][ut.default_float_vec_field_name] == binary_entities[2]["values"][0]
|
assert res[2][ut.default_float_vec_field_name] == binary_entities[2]["values"][0]
|
||||||
|
|
||||||
|
@pytest.mark.level(2)
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
def test_query_expr_all_term_array(self, connect, collection):
|
def test_query_expr_all_term_array(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query with all array term expr
|
target: test query with all array term expr
|
||||||
|
@ -368,32 +338,12 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
int_values = entities[0]["values"]
|
term_expr = f'{default_int_field_name} in {ids}'
|
||||||
term_expr = f'{default_int_field_name} in {int_values}'
|
|
||||||
res = connect.query(collection, term_expr)
|
res = connect.query(collection, term_expr)
|
||||||
assert len(res) == ut.default_nb
|
assert len(res) == ut.default_nb
|
||||||
for i in ut.default_nb:
|
for i in range(ut.default_nb):
|
||||||
assert res[i][default_int_field_name] == int_values[i]
|
|
||||||
|
|
||||||
def test_query_expr_half_term_array(self, connect, collection):
|
|
||||||
"""
|
|
||||||
target: test query with half array term expr
|
|
||||||
method: query with half array value
|
|
||||||
expected: verify query result
|
|
||||||
"""
|
|
||||||
entities, ids = init_data(connect, collection)
|
|
||||||
assert len(ids) == ut.default_nb
|
|
||||||
half = ut.default_nb // 2
|
|
||||||
connect.flush(collection)
|
|
||||||
int_values = entities[0]["values"][:half]
|
|
||||||
term_expr = f'{default_int_field_name} in {int_values}'
|
|
||||||
res = connect.query(collection, term_expr)
|
|
||||||
assert len(res) == half
|
|
||||||
for i in half:
|
|
||||||
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
assert res[i][default_float_field_name] == entities[1]["values"][i]
|
|
||||||
assert res[i][ut.default_float_vec_field_name] == entities[2]["values"][i]
|
|
||||||
|
|
||||||
def test_query_expr_repeated_term_array(self, connect, collection):
|
def test_query_expr_repeated_term_array(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -403,10 +353,11 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
|
connect.load_collection(collection)
|
||||||
int_values = [0, 0]
|
int_values = [0, 0]
|
||||||
term_expr = f'{default_int_field_name} in {int_values}'
|
term_expr = f'{default_int_field_name} in {int_values}'
|
||||||
res = connect.query(collection, term_expr)
|
res = connect.query(collection, term_expr)
|
||||||
assert len(res) == 1
|
assert len(res) == 2
|
||||||
|
|
||||||
def test_query_expr_inconstant_term_array(self, connect, collection):
|
def test_query_expr_inconstant_term_array(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -416,10 +367,9 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
expr = f'{default_int_field_name} in [1., 2.]'
|
expr = f'{default_int_field_name} in [1.0, 2.0]'
|
||||||
msg = 'invalid expr'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
def test_query_expr_mix_term_array(self, connect, collection):
|
def test_query_expr_mix_term_array(self, connect, collection):
|
||||||
|
@ -430,13 +380,12 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
expr = f'{default_int_field_name} in [1, 2.]'
|
expr = f'{default_int_field_name} in [1, 2.]'
|
||||||
msg = 'invalid expr'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
@pytest.mark.parametrize("constant", [[1], (), {}, " "])
|
@pytest.mark.parametrize("constant", [[1], (), {}])
|
||||||
def test_query_expr_non_constant_array_term(self, connect, collection, constant):
|
def test_query_expr_non_constant_array_term(self, connect, collection, constant):
|
||||||
"""
|
"""
|
||||||
target: test query with non-constant array term expr
|
target: test query with non-constant array term expr
|
||||||
|
@ -445,13 +394,12 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
expr = f'{default_int_field_name} in [{constant}]'
|
expr = f'{default_int_field_name} in [{constant}]'
|
||||||
msg = 'invalid expr'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, expr)
|
connect.query(collection, expr)
|
||||||
|
|
||||||
def test_query_output_field_none(self, connect, collection):
|
def test_query_output_field_empty(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query with none output field
|
target: test query with none output field
|
||||||
method: query with output field=None
|
method: query with output field=None
|
||||||
|
@ -459,10 +407,11 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
res = connect.query(collection, default_term_expr, output_fields=None)
|
res = connect.query(collection, default_term_expr, output_fields=[])
|
||||||
fields = [default_int_field_name, default_float_field_name, ut.default_float_vec_field_name]
|
fields = [default_int_field_name, default_float_field_name, ut.default_float_vec_field_name]
|
||||||
assert res[0].keys() == fields
|
for field in fields:
|
||||||
|
assert field in res[0].keys()
|
||||||
|
|
||||||
def test_query_output_one_field(self, connect, collection):
|
def test_query_output_one_field(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -472,9 +421,10 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
res = connect.query(collection, default_term_expr, output_fields=[default_int_field_name])
|
res = connect.query(collection, default_term_expr, output_fields=[default_int_field_name])
|
||||||
assert res[0].keys() == [default_int_field_name]
|
assert default_int_field_name in res[0].keys()
|
||||||
|
assert len(res[0].keys()) == 1
|
||||||
|
|
||||||
def test_query_output_all_fields(self, connect, collection):
|
def test_query_output_all_fields(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -484,10 +434,11 @@ class TestQueryBase:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.flush(collection)
|
connect.load_collection(collection)
|
||||||
fields = [default_int_field_name, default_float_field_name, ut.default_float_vec_field_name]
|
fields = [default_int_field_name, default_float_field_name, ut.default_float_vec_field_name]
|
||||||
res = connect.query(collection, default_term_expr, output_fields=fields)
|
res = connect.query(collection, default_term_expr, output_fields=fields)
|
||||||
assert res[0].keys() == fields
|
for field in fields:
|
||||||
|
assert field in res[0].keys()
|
||||||
|
|
||||||
def test_query_output_not_existed_field(self, connect, collection):
|
def test_query_output_not_existed_field(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -496,12 +447,11 @@ class TestQueryBase:
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
connect.load_collection(collection)
|
||||||
connect.flush(collection)
|
with pytest.raises(Exception):
|
||||||
msg = 'cannot find field'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr, output_fields=["int"])
|
connect.query(collection, default_term_expr, output_fields=["int"])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6074")
|
||||||
def test_query_output_part_not_existed_field(self, connect, collection):
|
def test_query_output_part_not_existed_field(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query output part not existed field
|
target: test query output part not existed field
|
||||||
|
@ -509,25 +459,10 @@ class TestQueryBase:
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
connect.load_collection(collection)
|
||||||
connect.flush(collection)
|
with pytest.raises(Exception):
|
||||||
msg = 'cannot find field'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr, output_fields=[default_int_field_name, "int"])
|
connect.query(collection, default_term_expr, output_fields=[default_int_field_name, "int"])
|
||||||
|
|
||||||
def test_query_empty_output_fields(self, connect, collection):
|
|
||||||
"""
|
|
||||||
target: test query with empty output fields
|
|
||||||
method: query with empty output fields
|
|
||||||
expected: raise exception
|
|
||||||
"""
|
|
||||||
entities, ids = init_data(connect, collection)
|
|
||||||
assert len(ids) == ut.default_nb
|
|
||||||
connect.flush(collection)
|
|
||||||
msg = 'output fields is empty'
|
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr, output_fields=[])
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("fields", ut.gen_invalid_strs())
|
@pytest.mark.parametrize("fields", ut.gen_invalid_strs())
|
||||||
def test_query_invalid_output_fields(self, connect, collection, fields):
|
def test_query_invalid_output_fields(self, connect, collection, fields):
|
||||||
"""
|
"""
|
||||||
|
@ -536,20 +471,17 @@ class TestQueryBase:
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
connect.load_collection(collection)
|
||||||
connect.flush(collection)
|
with pytest.raises(Exception):
|
||||||
msg = 'invalid output fields'
|
connect.query(collection, default_term_expr, output_fields=[fields])
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr, output_fields=fields)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="waiting for collection update")
|
|
||||||
class TestQueryPartition:
|
class TestQueryPartition:
|
||||||
"""
|
"""
|
||||||
test Query interface
|
test Query interface
|
||||||
query(collection_name, expr, output_fields=None, partition_names=None, timeout=None)
|
query(collection_name, expr, output_fields=None, partition_names=None, timeout=None)
|
||||||
"""
|
"""
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
def test_query_partition(self, connect, collection):
|
def test_query_partition(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query on partition
|
target: test query on partition
|
||||||
|
@ -557,11 +489,13 @@ class TestQueryPartition:
|
||||||
expected: verify query result
|
expected: verify query result
|
||||||
"""
|
"""
|
||||||
connect.create_partition(collection, ut.default_tag)
|
connect.create_partition(collection, ut.default_tag)
|
||||||
entities, ids = init_data(connect, collection, ut.default_tag)
|
entities, ids = init_data(connect, collection, partition_names=ut.default_tag)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.load_partitions(collection, [ut.default_tag])
|
connect.load_partitions(collection, [ut.default_tag])
|
||||||
res = connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
res = connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
||||||
# todo res
|
for i in range(default_pos):
|
||||||
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
|
ut.assert_equal_vector(res[i][ut.default_float_vec_field_name], entities[-1]["values"][i])
|
||||||
|
|
||||||
def test_query_partition_without_loading(self, connect, collection):
|
def test_query_partition_without_loading(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
|
@ -570,12 +504,12 @@ class TestQueryPartition:
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
connect.create_partition(collection, ut.default_tag)
|
connect.create_partition(collection, ut.default_tag)
|
||||||
entities, ids = init_data(connect, collection, ut.default_tag)
|
entities, ids = init_data(connect, collection, partition_names=ut.default_tag)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
msg = 'cannot find collection'
|
with pytest.raises(Exception):
|
||||||
with pytest.raises(Exception, match=msg):
|
|
||||||
connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
def test_query_default_partition(self, connect, collection):
|
def test_query_default_partition(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query on default partition
|
target: test query on default partition
|
||||||
|
@ -584,10 +518,13 @@ class TestQueryPartition:
|
||||||
"""
|
"""
|
||||||
entities, ids = init_data(connect, collection)
|
entities, ids = init_data(connect, collection)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.load_partitions(collection, [ut.default_tag])
|
connect.load_collection(collection)
|
||||||
res = connect.query(collection, default_term_expr, partition_names=[ut.default_partition_name])
|
res = connect.query(collection, default_term_expr, partition_names=[ut.default_partition_name])
|
||||||
# todo res
|
for i in range(default_pos):
|
||||||
|
assert res[i][default_int_field_name] == entities[0]["values"][i]
|
||||||
|
ut.assert_equal_vector(res[i][ut.default_float_vec_field_name], entities[-1]["values"][i])
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6075")
|
||||||
def test_query_empty_partition(self, connect, collection):
|
def test_query_empty_partition(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query on empty partition
|
target: test query on empty partition
|
||||||
|
@ -595,7 +532,7 @@ class TestQueryPartition:
|
||||||
expected: empty query result
|
expected: empty query result
|
||||||
"""
|
"""
|
||||||
connect.create_partition(collection, ut.default_tag)
|
connect.create_partition(collection, ut.default_tag)
|
||||||
connect.load_partitions(collection, [ut.default_tag])
|
connect.load_partitions(collection, [ut.default_partition_name])
|
||||||
res = connect.query(collection, default_term_expr, partition_names=[ut.default_partition_name])
|
res = connect.query(collection, default_term_expr, partition_names=[ut.default_partition_name])
|
||||||
assert len(res) == 0
|
assert len(res) == 0
|
||||||
|
|
||||||
|
@ -605,10 +542,9 @@ class TestQueryPartition:
|
||||||
method: query on not existed partition
|
method: query on not existed partition
|
||||||
expected: raise exception
|
expected: raise exception
|
||||||
"""
|
"""
|
||||||
connect.load_partitions(collection, [ut.default_tag])
|
connect.load_partitions(collection, [ut.default_partition_name])
|
||||||
msg = 'cannot find partition'
|
|
||||||
tag = ut.gen_unique_str()
|
tag = ut.gen_unique_str()
|
||||||
with pytest.raises(Exception, match=msg):
|
with pytest.raises(Exception):
|
||||||
connect.query(collection, default_term_expr, partition_names=[tag])
|
connect.query(collection, default_term_expr, partition_names=[tag])
|
||||||
|
|
||||||
def test_query_partition_repeatedly(self, connect, collection):
|
def test_query_partition_repeatedly(self, connect, collection):
|
||||||
|
@ -618,7 +554,7 @@ class TestQueryPartition:
|
||||||
expected: verify query result
|
expected: verify query result
|
||||||
"""
|
"""
|
||||||
connect.create_partition(collection, ut.default_tag)
|
connect.create_partition(collection, ut.default_tag)
|
||||||
entities, ids = init_data(connect, collection, ut.default_tag)
|
entities, ids = init_data(connect, collection, partition_names=ut.default_tag)
|
||||||
assert len(ids) == ut.default_nb
|
assert len(ids) == ut.default_nb
|
||||||
connect.load_partitions(collection, [ut.default_tag])
|
connect.load_partitions(collection, [ut.default_tag])
|
||||||
res_one = connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
res_one = connect.query(collection, default_term_expr, partition_names=[ut.default_tag])
|
||||||
|
@ -638,6 +574,7 @@ class TestQueryPartition:
|
||||||
res = connect.query(collection, term_expr, partition_names=[ut.default_tag])
|
res = connect.query(collection, term_expr, partition_names=[ut.default_tag])
|
||||||
assert len(res) == 0
|
assert len(res) == 0
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="#6070")
|
||||||
def test_query_multi_partitions_multi_results(self, connect, collection):
|
def test_query_multi_partitions_multi_results(self, connect, collection):
|
||||||
"""
|
"""
|
||||||
target: test query on multi partitions and get multi results
|
target: test query on multi partitions and get multi results
|
||||||
|
|
|
@ -3,7 +3,6 @@ log_format = [%(asctime)s-%(levelname)s-%(name)s]: %(message)s (%(filename)s:%(l
|
||||||
log_date_format = %Y-%m-%d %H:%M:%S
|
log_date_format = %Y-%m-%d %H:%M:%S
|
||||||
|
|
||||||
log_cli = true
|
log_cli = true
|
||||||
addopts = -x
|
|
||||||
log_level = 20
|
log_level = 20
|
||||||
|
|
||||||
timeout = 360
|
timeout = 360
|
||||||
|
|
Loading…
Reference in New Issue