Skip to content

Commit 5460c02

Browse files
MrPresent-HanMrPresent-Han
and
MrPresent-Han
authored
fix: iterator mismatch when alter alias and database(#2555) (#2568)
related: #2555 Signed-off-by: MrPresent-Han <[email protected]> Co-authored-by: MrPresent-Han <[email protected]>
1 parent 3a2abe0 commit 5460c02

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

pymilvus/client/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DEFAULT_CONSISTENCY_LEVEL = ConsistencyLevel.Bounded
1010
DEFAULT_RESOURCE_GROUP = "__default_resource_group"
1111
REDUCE_STOP_FOR_BEST = "reduce_stop_for_best"
12+
COLLECTION_ID = "collection_id"
1213
GROUP_BY_FIELD = "group_by_field"
1314
ITERATOR_FIELD = "iterator"
1415
PAGE_RETAIN_ORDER_FIELD = "page_retain_order"

pymilvus/client/prepare.py

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import __version__, blob, check, entity_helper, ts_utils, utils
1515
from .check import check_pass_param, is_legal_collection_properties
1616
from .constants import (
17+
COLLECTION_ID,
1718
DEFAULT_CONSISTENCY_LEVEL,
1819
GROUP_BY_FIELD,
1920
ITERATOR_FIELD,
@@ -861,6 +862,10 @@ def search_requests_with_expr(
861862
if is_iterator is not None:
862863
search_params[ITERATOR_FIELD] = is_iterator
863864

865+
collection_id = kwargs.get(COLLECTION_ID)
866+
if collection_id is not None:
867+
search_params[COLLECTION_ID] = str(collection_id)
868+
864869
group_by_field = kwargs.get(GROUP_BY_FIELD)
865870
if group_by_field is not None:
866871
search_params[GROUP_BY_FIELD] = group_by_field
@@ -1145,6 +1150,11 @@ def query_request(
11451150
consistency_level=kwargs.get("consistency_level", 0),
11461151
expr_template_values=cls.prepare_expression_template(kwargs.get("expr_params", {})),
11471152
)
1153+
collection_id = kwargs.get(COLLECTION_ID)
1154+
if collection_id is not None:
1155+
req.query_params.append(
1156+
common_types.KeyValuePair(key=COLLECTION_ID, value=str(collection_id))
1157+
)
11481158

11491159
limit = kwargs.get("limit")
11501160
if limit is not None:

pymilvus/orm/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
EF = "ef"
4040
IS_PRIMARY = "is_primary"
4141
REDUCE_STOP_FOR_BEST = "reduce_stop_for_best"
42+
COLLECTION_ID = "collection_id"
4243
ITERATOR_FIELD = "iterator"
4344
DEFAULT_MAX_L2_DISTANCE = 99999999.0
4445
DEFAULT_MIN_IP_DISTANCE = -99999999.0

pymilvus/orm/iterator.py

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
CALC_DIST_JACCARD,
2020
CALC_DIST_L2,
2121
CALC_DIST_TANIMOTO,
22+
COLLECTION_ID,
2223
DEFAULT_SEARCH_EXTENSION_RATE,
2324
EF,
2425
FIELDS,
@@ -72,11 +73,14 @@ def __init__(
7273
) -> QueryIterator:
7374
self._conn = connection
7475
self._collection_name = collection_name
76+
self.__set_up_collection_id()
7577
self._output_fields = output_fields
7678
self._partition_names = partition_names
7779
self._schema = schema
7880
self._timeout = timeout
7981
self._kwargs = kwargs
82+
self._kwargs[ITERATOR_FIELD] = "True"
83+
self._kwargs[COLLECTION_ID] = self._collection_id
8084
self.__check_set_batch_size(batch_size)
8185
self._limit = limit
8286
self.__check_set_reduce_stop_for_best()
@@ -87,6 +91,10 @@ def __init__(
8791
self.__seek()
8892
self._cache_id_in_use = NO_CACHE_ID
8993

94+
def __set_up_collection_id(self):
95+
res = self._conn.describe_collection(self._collection_name)
96+
self._collection_id = res[COLLECTION_ID]
97+
9098
def __check_set_reduce_stop_for_best(self):
9199
if self._kwargs.get(REDUCE_STOP_FOR_BEST, True):
92100
self._kwargs[REDUCE_STOP_FOR_BEST] = "True"
@@ -336,11 +344,14 @@ def __init__(
336344
"timeout": timeout,
337345
"round_decimal": round_decimal,
338346
}
347+
self._collection_name = collection_name
339348
self._expr = expr
340349
self.__check_set_params(param)
341350
self.__check_for_special_index_param()
342351
self._kwargs = kwargs
343352
self.__set_up_iteration_states()
353+
self.__set_up_collection_id()
354+
self._kwargs[COLLECTION_ID] = self._collection_id
344355
self._filtered_ids = []
345356
self._filtered_distance = None
346357
self._schema = schema
@@ -352,6 +363,10 @@ def __init__(
352363
self.__setup__pk_prop()
353364
self.__init_search_iterator()
354365

366+
def __set_up_collection_id(self):
367+
res = self._conn.describe_collection(self._collection_name)
368+
self._collection_id = res[COLLECTION_ID]
369+
355370
def __init_search_iterator(self):
356371
init_page = self.__execute_next_search(self._param, self._expr, False)
357372
if len(init_page) == 0:

0 commit comments

Comments
 (0)