Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: alterindex & altercollection supports altering properties #2339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def _check():
return Status(status.code, status.reason)

@retry_on_rpc_failure()
def alter_index(
def alter_index_properties(
self,
collection_name: str,
index_name: str,
Expand All @@ -1012,10 +1012,27 @@ def alter_index(
**kwargs,
):
check_pass_param(collection_name=collection_name, index_name=index_name, timeout=timeout)
if extra_params is None:
raise ParamError(message="extra_params should not be None")
request = Prepare.alter_index_properties_request(
collection_name, index_name, extra_params=extra_params
)

request = Prepare.alter_index_request(collection_name, index_name, extra_params)
rf = self._stub.AlterIndex.future(request, timeout=timeout)
response = rf.result()
check_status(response)

@retry_on_rpc_failure()
def drop_index_properties(
self,
collection_name: str,
index_name: str,
delete_keys: List[str],
timeout: Optional[float] = None,
**kwargs,
):
check_pass_param(collection_name=collection_name, index_name=index_name, timeout=timeout)
request = Prepare.drop_index_properties_request(
collection_name, index_name, delete_keys=delete_keys
)

rf = self._stub.AlterIndex.future(request, timeout=timeout)
response = rf.result()
Expand Down
12 changes: 11 additions & 1 deletion pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,14 +1012,24 @@ def create_index_request(cls, collection_name: str, field_name: str, params: Dic
return index_params

@classmethod
def alter_index_request(cls, collection_name: str, index_name: str, extra_params: dict):
def alter_index_properties_request(
cls, collection_name: str, index_name: str, extra_params: dict
):
params = []
for k, v in extra_params.items():
params.append(common_types.KeyValuePair(key=str(k), value=utils.dumps(v)))
return milvus_types.AlterIndexRequest(
collection_name=collection_name, index_name=index_name, extra_params=params
)

@classmethod
def drop_index_properties_request(
cls, collection_name: str, index_name: str, delete_keys: List[str]
):
return milvus_types.AlterIndexRequest(
collection_name=collection_name, index_name=index_name, delete_keys=delete_keys
)

@classmethod
def describe_index_request(
cls, collection_name: str, index_name: str, timestamp: Optional[int] = None
Expand Down
26 changes: 26 additions & 0 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,32 @@ def describe_index(
conn = self._get_connection()
return conn.describe_index(collection_name, index_name, timeout=timeout, **kwargs)

def alter_index_properties(
self,
collection_name: str,
index_name: str,
extra_params: dict,
timeout: Optional[float] = None,
**kwargs,
):
conn = self._get_connection()
conn.alter_index_properties(
collection_name, index_name, extra_params=extra_params, timeout=timeout, **kwargs
)

def drop_index_properties(
self,
collection_name: str,
index_name: str,
delete_keys: List[str],
timeout: Optional[float] = None,
**kwargs,
):
conn = self._get_connection()
conn.alter_index_properties(
collection_name, index_name, delete_keys=delete_keys, timeout=timeout, **kwargs
)

def create_partition(
self, collection_name: str, partition_name: str, timeout: Optional[float] = None, **kwargs
):
Expand Down
17 changes: 15 additions & 2 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ def create_index(
conn = self._get_connection()
return conn.create_index(self._name, field_name, index_params, timeout=timeout, **kwargs)

def alter_index(
def alter_index_properties(
self,
index_name: str,
extra_params: dict,
Expand Down Expand Up @@ -1412,7 +1412,20 @@ def alter_index(
>>> collection.alter_index("idx", {"mmap.enabled": True})
"""
conn = self._get_connection()
return conn.alter_index(self._name, index_name, extra_params, timeout=timeout)
return conn.alter_index_properties(
self._name, index_name, extra_params=extra_params, timeout=timeout
)

def drop_index_properties(
self,
index_name: str,
delete_keys: List[str],
timeout: Optional[float] = None,
):
conn = self._get_connection()
return conn.drop_index_properties(
self._name, index_name, delete_keys=delete_keys, timeout=timeout
)

def has_index(self, timeout: Optional[float] = None, **kwargs) -> bool:
"""Check whether a specified index exists.
Expand Down