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 #2432

Merged
merged 8 commits into from
Dec 12, 2024
Merged
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
62 changes: 55 additions & 7 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
@@ -320,11 +320,42 @@ def drop_collection(self, collection_name: str, timeout: Optional[float] = None)
check_status(status)

@retry_on_rpc_failure()
def alter_collection(
def alter_collection_properties(
self, collection_name: str, properties: List, timeout: Optional[float] = None, **kwargs
):
check_pass_param(collection_name=collection_name, properties=properties, timeout=timeout)
request = Prepare.alter_collection_request(collection_name, properties)
request = Prepare.alter_collection_request(collection_name, properties=properties)
rf = self._stub.AlterCollection.future(request, timeout=timeout)
status = rf.result()
check_status(status)

@retry_on_rpc_failure()
def alter_collection_field_properties(
self,
collection_name: str,
field_name: str,
field_param: List,
timeout: Optional[float] = None,
**kwargs,
):
check_pass_param(collection_name=collection_name, properties=field_param, timeout=timeout)
request = Prepare.alter_collection_field_request(
self, collection_name=collection_name, field_name=field_name, field_param=field_param
)
rf = self._stub.AlterCollectionField.future(request, timeout=timeout)
status = rf.result()
check_status(status)

@retry_on_rpc_failure()
def drop_collection_properties(
self,
collection_name: str,
property_keys: List[str],
timeout: Optional[float] = None,
**kwargs,
):
check_pass_param(collection_name=collection_name, timeout=timeout)
request = Prepare.alter_collection_request(collection_name, delete_keys=property_keys)
rf = self._stub.AlterCollection.future(request, timeout=timeout)
status = rf.result()
check_status(status)
@@ -1003,24 +1034,41 @@ 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,
extra_params: dict,
properties: dict,
timeout: Optional[float] = None,
**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")
if properties is None:
raise ParamError(message="properties should not be None")

request = Prepare.alter_index_request(collection_name, index_name, extra_params)
request = Prepare.alter_index_properties_request(collection_name, index_name, properties)

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,
property_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=property_keys
)
rf = self._stub.AlterIndex.future(request, timeout=timeout)
response = rf.result()
check_status(response)

@retry_on_rpc_failure()
def list_indexes(self, collection_name: str, timeout: Optional[float] = None, **kwargs):
check_pass_param(collection_name=collection_name, timeout=timeout)
36 changes: 31 additions & 5 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
@@ -277,11 +277,27 @@ def describe_collection_request(
def alter_collection_request(
cls,
collection_name: str,
properties: Dict,
properties: Optional[Dict] = None,
delete_keys: Optional[List[str]] = None,
) -> milvus_types.AlterCollectionRequest:
kvs = [common_types.KeyValuePair(key=k, value=str(v)) for k, v in properties.items()]
kvs = []
if properties:
kvs = [common_types.KeyValuePair(key=k, value=str(v)) for k, v in properties.items()]

return milvus_types.AlterCollectionRequest(
collection_name=collection_name, properties=kvs, delete_keys=delete_keys
)

return milvus_types.AlterCollectionRequest(collection_name=collection_name, properties=kvs)
@classmethod
def alter_collection_field_request(
cls, collection_name: str, field_name: str, field_param: Dict
) -> milvus_types.AlterCollectionFieldRequest:
kvs = []
if field_param:
kvs = [common_types.KeyValuePair(key=k, value=str(v)) for k, v in field_param.items()]
return milvus_types.AlterCollectionFieldRequest(
collection_name=collection_name, field_name=field_name, properties=kvs
)

@classmethod
def collection_stats_request(cls, collection_name: str):
@@ -1094,14 +1110,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, properties: dict
):
params = []
for k, v in extra_params.items():
for k, v in properties.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
Loading