Skip to content

Commit 6541247

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

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

pymilvus/client/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
DEFAULT_RESOURCE_GROUP = "__default_resource_group"
1111
DYNAMIC_FIELD_NAME = "$meta"
1212
REDUCE_STOP_FOR_BEST = "reduce_stop_for_best"
13+
COLLECTION_ID = "collection_id"
1314
GROUP_BY_FIELD = "group_by_field"
1415
GROUP_SIZE = "group_size"
1516
RANK_GROUP_SCORER = "rank_group_scorer"

pymilvus/client/prepare.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from . import __version__, blob, check, entity_helper, ts_utils, utils
1616
from .check import check_pass_param, is_legal_collection_properties
1717
from .constants import (
18+
COLLECTION_ID,
1819
DEFAULT_CONSISTENCY_LEVEL,
1920
DYNAMIC_FIELD_NAME,
2021
GROUP_BY_FIELD,
@@ -961,6 +962,10 @@ def search_requests_with_expr(
961962
if is_iterator is not None:
962963
search_params[ITERATOR_FIELD] = is_iterator
963964

965+
collection_id = kwargs.get(COLLECTION_ID)
966+
if collection_id is not None:
967+
search_params[COLLECTION_ID] = str(collection_id)
968+
964969
is_search_iter_v2 = kwargs.get(ITER_SEARCH_V2_KEY)
965970
if is_search_iter_v2 is not None:
966971
search_params[ITER_SEARCH_V2_KEY] = is_search_iter_v2
@@ -1310,6 +1315,11 @@ def query_request(
13101315
consistency_level=kwargs.get("consistency_level", 0),
13111316
expr_template_values=cls.prepare_expression_template(kwargs.get("expr_params", {})),
13121317
)
1318+
collection_id = kwargs.get(COLLECTION_ID)
1319+
if collection_id is not None:
1320+
req.query_params.append(
1321+
common_types.KeyValuePair(key=COLLECTION_ID, value=str(collection_id))
1322+
)
13131323

13141324
limit = kwargs.get("limit")
13151325
if limit is not None:

pymilvus/client/search_iterator.py

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pymilvus.client import entity_helper, utils
66
from pymilvus.client.abstract import Hits
77
from pymilvus.client.constants import (
8+
COLLECTION_ID,
89
GUARANTEE_TIMESTAMP,
910
ITER_SEARCH_BATCH_SIZE_KEY,
1011
ITER_SEARCH_ID_KEY,
@@ -50,6 +51,8 @@ def __init__(
5051
self._left_res_cnt = limit
5152

5253
self._conn = connection
54+
self.__set_up_collection_id(collection_name)
55+
kwargs[COLLECTION_ID] = self._collection_id
5356
self._params = {
5457
"collection_name": collection_name,
5558
"data": data,
@@ -71,6 +74,10 @@ def __init__(
7174
self._saved_first_res = self.next()
7275
self._is_saved = True
7376

77+
def __set_up_collection_id(self, collection_name: str):
78+
res = self._conn.describe_collection(collection_name)
79+
self._collection_id = res[COLLECTION_ID]
80+
7481
def next(self):
7582
# for compatibility
7683
if self._is_saved:

pymilvus/orm/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
EF = "ef"
4848
IS_PRIMARY = "is_primary"
4949
REDUCE_STOP_FOR_BEST = "reduce_stop_for_best"
50+
COLLECTION_ID = "collection_id"
5051
ITERATOR_FIELD = "iterator"
5152
ITERATOR_SESSION_TS_FIELD = "iterator_session_ts"
5253
DEFAULT_MAX_L2_DISTANCE = 99999999.0

pymilvus/orm/iterator.py

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CALC_DIST_JACCARD,
2424
CALC_DIST_L2,
2525
CALC_DIST_TANIMOTO,
26+
COLLECTION_ID,
2627
DEFAULT_SEARCH_EXTENSION_RATE,
2728
EF,
2829
FIELDS,
@@ -101,13 +102,15 @@ def __init__(
101102
) -> QueryIterator:
102103
self._conn = connection
103104
self._collection_name = collection_name
105+
self.__set_up_collection_id()
104106
self._output_fields = output_fields
105107
self._partition_names = partition_names
106108
self._schema = schema
107109
self._timeout = timeout
108110
self._session_ts = 0
109111
self._kwargs = kwargs
110112
self._kwargs[ITERATOR_FIELD] = "True"
113+
self._kwargs[COLLECTION_ID] = self._collection_id
111114
self.__check_set_batch_size(batch_size)
112115
self._limit = limit
113116
self.__check_set_reduce_stop_for_best()
@@ -120,6 +123,10 @@ def __init__(
120123
self.__set_up_ts_cp()
121124
self.__seek_to_offset()
122125

126+
def __set_up_collection_id(self):
127+
res = self._conn.describe_collection(self._collection_name)
128+
self._collection_id = res[COLLECTION_ID]
129+
123130
def __seek_to_offset(self):
124131
# read pk cursor from cp file, no need to seek offset
125132
if self._next_id is not None:
@@ -502,6 +509,8 @@ def __init__(
502509
self.__check_for_special_index_param()
503510
self._kwargs = kwargs
504511
self._kwargs[ITERATOR_FIELD] = "True"
512+
self.__set_up_collection_id()
513+
self._kwargs[COLLECTION_ID] = self._collection_id
505514
self._filtered_ids = []
506515
self._filtered_distance = None
507516
self._schema = schema
@@ -513,6 +522,10 @@ def __init__(
513522
self.__setup__pk_prop()
514523
self.__init_search_iterator()
515524

525+
def __set_up_collection_id(self):
526+
res = self._conn.describe_collection(self._collection_name)
527+
self._collection_id = res[COLLECTION_ID]
528+
516529
def __init_search_iterator(self):
517530
init_page = self.__execute_next_search(self._param, self._expr, False)
518531
self._session_ts = init_page.get_session_ts()

0 commit comments

Comments
 (0)