Skip to content

Commit

Permalink
support None expr for QueryIterator(milvus-io/milvus#26357) (#1647)
Browse files Browse the repository at this point in the history
Signed-off-by: MrPresent-Han <[email protected]>
  • Loading branch information
MrPresent-Han authored Aug 16, 2023
1 parent 1313bdb commit 9acbc7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,14 +919,12 @@ def query(

def query_iterator(
self,
expr: str,
expr: Optional[str] = None,
output_fields: Optional[List[str]] = None,
partition_names: Optional[List[str]] = None,
timeout: Optional[float] = None,
**kwargs,
):
if not isinstance(expr, str):
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(expr))
return QueryIterator(
connection=self._get_connection(),
collection_name=self._name,
Expand Down
1 change: 1 addition & 0 deletions pymilvus/orm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
DEFAULT_MAX_JACCARD_DISTANCE = 2.0
DEFAULT_MIN_COSINE_DISTANCE = -2.0
MAX_FILTERED_IDS_COUNT_ITERATION = 100000
INT64_MAX = 9223372036854775807
18 changes: 14 additions & 4 deletions pymilvus/orm/iterator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import copy
from copy import deepcopy
from typing import Any, Dict, List, Optional, TypeVar

from pymilvus.exceptions import MilvusException
Expand All @@ -18,6 +18,7 @@
DEFAULT_MIN_COSINE_DISTANCE,
DEFAULT_MIN_IP_DISTANCE,
FIELDS,
INT64_MAX,
ITERATION_EXTENSION_REDUCE_RATE,
LIMIT,
MAX_FILTERED_IDS_COUNT_ITERATION,
Expand All @@ -39,7 +40,7 @@ def __init__(
self,
connection: Connections,
collection_name: str,
expr: str,
expr: Optional[str] = None,
output_fields: Optional[List[str]] = None,
partition_names: Optional[List[str]] = None,
schema: Optional[CollectionSchema] = None,
Expand All @@ -48,16 +49,25 @@ def __init__(
) -> QueryIterator:
self._conn = connection
self._collection_name = collection_name
self._expr = expr
self._output_fields = output_fields
self._partition_names = partition_names
self._schema = schema
self._timeout = timeout
self._kwargs = kwargs
self.__setup__pk_prop()
self.__set_up_expr(expr)
self.__seek()
self._cache_id_in_use = NO_CACHE_ID

# rely on pk prop, so this method should be called after __set_up_expr
def __set_up_expr(self, expr: str):
if expr is not None:
self._expr = expr
elif self._pk_str:
self._expr = self._pk_field_name + ' != ""'
else:
self._expr = self._pk_field_name + " < " + str(INT64_MAX)

def __seek(self):
self._cache_id_in_use = NO_CACHE_ID
if self._kwargs.get(OFFSET, 0) == 0:
Expand Down Expand Up @@ -213,7 +223,7 @@ def __check_set_params(self, param: Dict):
if param is None:
self._param = {}
else:
self._param = copy.deepcopy(param)
self._param = deepcopy(param)

def __setup__pk_prop(self):
fields = self._schema[FIELDS]
Expand Down

0 comments on commit 9acbc7e

Please sign in to comment.