Skip to content

Commit

Permalink
test:[cherry-pick] Add upsert with autoid and update init collection …
Browse files Browse the repository at this point in the history
…method (#35624)

Related issue: #32653
pr:  #35596

---------

Signed-off-by: yanliang567 <[email protected]>
  • Loading branch information
yanliang567 authored Aug 22, 2024
1 parent e2542a1 commit d7d4525
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 264 deletions.
4 changes: 2 additions & 2 deletions tests/python_client/base/collection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ def upsert(self, data, partition_name=None, timeout=None, check_task=None, check
return res, check_result

@trace()
def compact(self, timeout=None, check_task=None, check_items=None, **kwargs):
def compact(self, is_clustering=False, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
func_name = sys._getframe().f_code.co_name
res, check = api_request([self.collection.compact, timeout], **kwargs)
res, check = api_request([self.collection.compact, is_clustering, timeout], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

Expand Down
4 changes: 2 additions & 2 deletions tests/python_client/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ allure-pytest==2.7.0
pytest-print==0.2.1
pytest-level==0.1.1
pytest-xdist==2.5.0
pymilvus==2.4.5rc11
pymilvus[bulk_writer]==2.4.5rc11
pymilvus==2.4.6rc4
pymilvus[bulk_writer]==2.4.6rc4
pytest-rerunfailures==9.1.1
git+https://github.com/Projectplace/pytest-tags
ndg-httpsclient
Expand Down
32 changes: 14 additions & 18 deletions tests/python_client/testcases/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ def test_alias_create_operation_default(self):

alias_name = cf.gen_unique_str(prefix)
self.utility_wrap.create_alias(collection_w.name, alias_name)
collection_alias, _ = self.collection_wrap.init_collection(name=alias_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_name,
exp_schema: default_schema})
collection_alias = self.init_collection_wrap(name=alias_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_name, exp_schema: default_schema})
# assert collection is equal to alias according to partitions
assert [p.name for p in collection_w.partitions] == [
p.name for p in collection_alias.partitions]
Expand Down Expand Up @@ -110,10 +109,9 @@ def test_alias_alter_operation_default(self):

alias_a_name = cf.gen_unique_str(prefix)
self.utility_wrap.create_alias(collection_1.name, alias_a_name)
collection_alias_a, _ = self.collection_wrap.init_collection(name=alias_a_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_a_name,
exp_schema: default_schema})
collection_alias_a = self.init_collection_wrap(name=alias_a_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_a_name, exp_schema: default_schema})
# assert collection is equal to alias according to partitions
assert [p.name for p in collection_1.partitions] == [
p.name for p in collection_alias_a.partitions]
Expand All @@ -132,10 +130,9 @@ def test_alias_alter_operation_default(self):

alias_b_name = cf.gen_unique_str(prefix)
self.utility_wrap.create_alias(collection_2.name, alias_b_name)
collection_alias_b, _ = self.collection_wrap.init_collection(name=alias_b_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_b_name,
exp_schema: default_schema})
collection_alias_b = self.init_collection_wrap(name=alias_b_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_b_name, exp_schema: default_schema})
# assert collection is equal to alias according to partitions
assert [p.name for p in collection_2.partitions] == [
p.name for p in collection_alias_b.partitions]
Expand Down Expand Up @@ -177,10 +174,9 @@ def test_alias_drop_operation_default(self):
alias_name = cf.gen_unique_str(prefix)
self.utility_wrap.create_alias(collection_w.name, alias_name)
# collection_w.create_alias(alias_name)
collection_alias, _ = self.collection_wrap.init_collection(name=alias_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_name,
exp_schema: default_schema})
collection_alias = self.init_collection_wrap(name=alias_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_name, exp_schema: default_schema})
# assert collection is equal to alias according to partitions
assert [p.name for p in collection_w.partitions] == [
p.name for p in collection_alias.partitions]
Expand Down Expand Up @@ -406,15 +402,15 @@ def test_enable_mmap_by_alias(self):
"""
self._connect()
c_name = cf.gen_unique_str("collection")
collection_w, _ = self.collection_wrap.init_collection(c_name, schema=default_schema)
collection_w = self.init_collection_wrap(c_name, schema=default_schema)
alias_name = cf.gen_unique_str(prefix)
self.utility_wrap.create_alias(collection_w.name, alias_name)
collection_alias, _ = self.collection_wrap.init_collection(name=alias_name,
check_task=CheckTasks.check_collection_property,
check_items={exp_name: alias_name,
exp_schema: default_schema})
collection_alias.set_properties({'mmap.enabled': True})
pro = collection_w.describe().get("properties")
pro = collection_w.describe()[0].get("properties")
assert pro["mmap.enabled"] == 'True'
collection_w.set_properties({'mmap.enabled': False})
pro = collection_alias.describe().get("properties")
Expand Down
2 changes: 1 addition & 1 deletion tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def test_collection_auto_id_inconsistent(self, auto_id):
int_field = cf.gen_int64_field(is_primary=True, auto_id=auto_id)
vec_field = cf.gen_float_vec_field(name='vec')
schema, _ = self.collection_schema_wrap.init_collection_schema([int_field, vec_field], auto_id=not auto_id)
collection_w = self.collection_wrap.init_collection(cf.gen_unique_str(prefix), schema=schema)[0]
collection_w = self.init_collection_wrap(cf.gen_unique_str(prefix), schema=schema)

assert collection_w.schema.auto_id is auto_id

Expand Down
30 changes: 16 additions & 14 deletions tests/python_client/testcases/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,24 +923,24 @@ def test_turn_off_index_mmap(self):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
collection_w, _ = self.collection_wrap.init_collection(c_name, schema=default_schema)
collection_w = self.init_collection_wrap(c_name, schema=default_schema)
collection_w.insert(cf.gen_default_list_data())
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
index_name=ct.default_index_name)
collection_w.alter_index(ct.default_index_name, {'mmap.enabled': True})
assert collection_w.index().params["mmap.enabled"] == 'True'
assert collection_w.index()[0].params["mmap.enabled"] == 'True'
collection_w.load()
collection_w.release()
collection_w.alter_index(ct.default_index_name, {'mmap.enabled': False})
collection_w.load()
assert collection_w.index().params["mmap.enabled"] == 'False'
assert collection_w.index()[0].params["mmap.enabled"] == 'False'
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
collection_w.search(vectors[:default_nq], default_search_field,
default_search_params, default_limit,
default_search_exp)
collection_w.release()
collection_w.alter_index(ct.default_index_name, {'mmap.enabled': True})
assert collection_w.index().params["mmap.enabled"] == 'True'
assert collection_w.index()[0].params["mmap.enabled"] == 'True'
collection_w.load()
collection_w.search(vectors[:default_nq], default_search_field,
default_search_params, default_limit,
Expand All @@ -958,12 +958,11 @@ def test_drop_mmap_index(self, index, params):
expected: search success
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
collection_w, _ = self.collection_wrap.init_collection(c_name, schema=cf.gen_default_collection_schema())
collection_w = self.init_collection_general(prefix, insert_data=True, is_index=False)[0]
default_index = {"index_type": index, "params": params, "metric_type": "L2"}
collection_w.create_index(field_name, default_index, index_name=f"mmap_index_{index}")
collection_w.alter_index(f"mmap_index_{index}", {'mmap.enabled': True})
assert collection_w.index().params["mmap.enabled"] == 'True'
assert collection_w.index()[0].params["mmap.enabled"] == 'True'
collection_w.drop_index(index_name=f"mmap_index_{index}")
collection_w.create_index(field_name, default_index, index_name=f"index_{index}")
collection_w.load()
Expand All @@ -984,30 +983,30 @@ def test_rebuild_mmap_index(self):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
collection_w, _ = self.collection_wrap.init_collection(c_name, schema=default_schema)
collection_w = self.init_collection_general(c_name, insert_data=True, is_index=False)[0]
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
index_name=ct.default_index_name)
collection_w.set_properties({'mmap.enabled': True})
pro = collection_w.describe().get("properties")
pro = collection_w.describe()[0].get("properties")
assert pro["mmap.enabled"] == 'True'
collection_w.alter_index(ct.default_index_name, {'mmap.enabled': True})
assert collection_w.index().params["mmap.enabled"] == 'True'
assert collection_w.index()[0].params["mmap.enabled"] == 'True'
collection_w.insert(cf.gen_default_list_data())
collection_w.flush()

# check if mmap works after rebuild index
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
index_name=ct.default_index_name)
assert collection_w.index().params["mmap.enabled"] == 'True'
assert collection_w.index()[0].params["mmap.enabled"] == 'True'

collection_w.load()
collection_w.release()

# check if mmap works after reloading and rebuilding index.
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
index_name=ct.default_index_name)
assert collection_w.index().params["mmap.enabled"] == 'True'
pro = collection_w.describe().get("properties")
assert collection_w.index()[0].params["mmap.enabled"] == 'True'
pro = collection_w.describe()[0].get("properties")
assert pro["mmap.enabled"] == 'True'

collection_w.load()
Expand Down Expand Up @@ -1305,14 +1304,17 @@ def test_create_inverted_index_on_array_field(self):
"""
target: test create scalar index on array field
method: 1.create collection, and create index
expected: Raise exception
expected: supported create inverted index on array since 2.4.x
"""
# 1. create a collection
schema = cf.gen_array_collection_schema()
collection_w = self.init_collection_wrap(schema=schema)
# 2. create index
scalar_index_params = {"index_type": "INVERTED"}
collection_w.create_index(ct.default_int32_array_field_name, index_params=scalar_index_params)
res, _ = self.utility_wrap.index_building_progress(collection_w.name, ct.default_int32_array_field_name)
exp_res = {'total_rows': 0, 'indexed_rows': 0, 'pending_index_rows': 0, 'state': 'Finished'}
assert res == exp_res

@pytest.mark.tags(CaseLabel.L1)
def test_create_inverted_index_no_vector_index(self):
Expand Down
Loading

0 comments on commit d7d4525

Please sign in to comment.