Skip to content

Commit

Permalink
enhance: alterindex & altercollection supports altering properties (#…
Browse files Browse the repository at this point in the history
…2406)

enhance :
alterindex delete properties
We have introduced a new parameter deleteKeys to the alterindex
functionality, which allows for the deletion of properties within an
index. This enhancement provides users with the flexibility to manage
index properties more effectively by removing specific keys as needed.
altercollection delete properties
We have introduced a new parameter deleteKeys to the altercollection
functionality, which allows for the deletion of properties within an
collection. This enhancement provides users with the flexibility to
manage collection properties more effectively by removing specific keys
as needed.
3.support altercollectionfield
We currently support modifying the fieldparams of a field in a
collection using altercollectionfield, which only allows changes to the
max-length attribute.
Key Points:
New Parameter - deleteKeys: This new parameter enables the deletion of
specified properties from an index. By passing a list of keys to
deleteKeys, users can remove the corresponding properties from the
index.
Mutual Exclusivity: The deleteKeys parameter cannot be used in
conjunction with the extraParams parameter. Users must choose one
parameter to pass based on their requirement. If deleteKeys is provided,
it indicates an intent to delete properties; if extraParams is provided,
it signifies the addition or update of properties.
issue :[#2338](#2338)

---------

Signed-off-by: Xianhui.Lin <[email protected]>
  • Loading branch information
JsDove authored Dec 10, 2024
1 parent 6feeaf3 commit 1f5255a
Show file tree
Hide file tree
Showing 9 changed files with 560 additions and 410 deletions.
62 changes: 55 additions & 7 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 31 additions & 5 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1f5255a

Please sign in to comment.