Skip to content

Commit

Permalink
Remove useless check function (#1510)
Browse files Browse the repository at this point in the history
Signed-off-by: longjiquan <[email protected]>
  • Loading branch information
longjiquan authored Jun 1, 2023
1 parent 237b469 commit a30d2f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 56 deletions.
37 changes: 2 additions & 35 deletions pymilvus/client/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
from ..exceptions import ParamError
from ..grpc_gen import milvus_pb2 as milvus_types
from .singleton_utils import Singleton
from .utils import (
valid_index_types,
valid_binary_index_types,
valid_index_params_keys,
)


def is_legal_address(addr: Any) -> bool:
Expand Down Expand Up @@ -353,42 +348,14 @@ def check(self, key, value):
else:
raise ParamError(message=f"unknown param `{key}`")


def _get_param_checker():
return ParamChecker()


def check_pass_param(*_args: Any, **kwargs: Any) -> None: # pylint: disable=too-many-statements
if kwargs is None:
raise ParamError(message="Param should not be None")
checker = _get_param_checker()
for key, value in kwargs.items():
checker.check(key, value)


def check_index_params(params):
params = params or {}
if not isinstance(params, dict):
raise ParamError(message="Params must be a dictionary type")
# params preliminary validate
if 'index_type' not in params:
raise ParamError(message="Params must contains key: 'index_type'")
if 'params' not in params:
raise ParamError(message="Params must contains key: 'params'")
if 'metric_type' not in params:
raise ParamError(message="Params must contains key: 'metric_type'")
if not isinstance(params['params'], dict):
raise ParamError(message="Params['params'] must be a dictionary type")
if params['index_type'] not in valid_index_types:
raise ParamError(message=f"Invalid index_type: {params['index_type']}, which must be one of: {str(valid_index_types)}")
for k in params['params'].keys():
if k not in valid_index_params_keys:
raise ParamError(message=f"Invalid params['params'].key: {k}")
for v in params['params'].values():
if not isinstance(v, int):
raise ParamError(message=f"Invalid params['params'].value: {v}, which must be an integer")
# filter invalid metric type
if params['index_type'] in valid_binary_index_types:
if not is_legal_binary_index_metric_type(params['index_type'], params['metric_type']):
raise ParamError(message=f"Invalid metric_type: {params['metric_type']}, which does not match the index type: {params['index_type']}")
else:
if not is_legal_index_metric_type(params['index_type'], params['metric_type']):
raise ParamError(message=f"Invalid metric_type: {params['metric_type']}, which does not match the index type: {params['index_type']}")
21 changes: 0 additions & 21 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pymilvus import MilvusException
from pymilvus.client.check import (
check_pass_param,
check_index_params
)
from pymilvus.client.utils import (
mkts_from_unixtime,
Expand Down Expand Up @@ -162,23 +161,3 @@ def test_version_re(self):

print(f"group {rv.group()}")
print(f"group {rv.groups()}")


class TestCheckIndexParams:
@pytest.mark.parametrize("invalid_params", [
["params type wrong", None],
["params missing index_type", {}],
["params missing params", {"index_type": "IVF_FLAT"}],
["params missing metric_type", {"index_type": "IVF_FLAT", "params": {}}],
["params.params not a dict", {"index_type": "IVF_FLAT", "metric_type": "L2", "params": None}],
["index_type invalid", {"index_type": "INVALID", "metric_type": "L2", "params": {}}],
["params index key invalid", {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"INVALID": 1}}],
["params index value invalid", {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": "INVALID"}}],
["float metric_type invalid", {"index_type": "IVF_FLAT", "metric_type": "INVALIE", "params": {"nlist": 1}}],
["binary metric_type invalid", {"index_type": "BIN_FLAT", "metric_type": "INVALIE", "params": {"nlist": 1}}],
["binary metric_type None", {"index_type": "BIN_FLAT", "metric_type": None, "params": {"nlist": 1}}],
])
def test_check_params_invalid(self, invalid_params):
with pytest.raises(MilvusException):
print(f"sub test: {invalid_params[0]}")
check_index_params(invalid_params[1])

0 comments on commit a30d2f1

Please sign in to comment.