Source code for milvus.client.utils

import datetime
from .exceptions import ParamError
from .types import MetricType, IndexType











[docs]def int_or_str(item): if isinstance(item, int): return str(item) return item
[docs]def is_correct_date_str(param): try: datetime.datetime.strptime(param, '%Y-%m-%d') except ValueError: raise ParamError('Incorrect data format, should be YYYY-MM-DD') return True
[docs]def parser_range_date(date): if isinstance(date, datetime.date): return date.strftime('%Y-%m-%d') if isinstance(date, str): if not is_correct_date_str(date): raise ParamError('Date string should be YY-MM-DD format!') return date raise ParamError( 'Date should be YY-MM-DD format string or datetime.date, ' 'or datetime.datetime object')
def _raise_param_error(param_name): raise ParamError("{} is illegal".format(param_name))
[docs]def check_pass_param(*args, **kwargs): if kwargs is None: raise ParamError("Param should not be None") for key, value in kwargs.items(): if key in ("table_name",): if not is_legal_table_name(value): _raise_param_error(key) elif key == "dimension": if not is_legal_dimension(value): _raise_param_error(key) elif key in ("index_type",): if not is_legal_index_type(value): _raise_param_error(key) elif key == "index_file_size": if not is_legal_index_size(value): _raise_param_error(key) elif key == "metric_type": if not is_legal_metric_type(value): _raise_param_error(key) elif key in ("topk", "top_k"): if not is_legal_topk(value): _raise_param_error(key) elif key in ("ids",): if not is_legal_ids(value): _raise_param_error(key) elif key in ("nprobe",): if not is_legal_nprobe(value): _raise_param_error(key) elif key in ("nlist",): if not is_legal_nlist(value): _raise_param_error(key) elif key in ("cmd",): if not is_legal_cmd(value): _raise_param_error(key)