26
26
import os
27
27
import urllib .parse
28
28
import uuid
29
- from typing import Callable , Dict , Any , Iterable , List , Mapping , Optional , Sequence , Tuple , Union , cast , Type
29
+ from typing import Callable , Dict , Any , Iterable , List , Mapping , Optional , Sequence , Tuple , Union , cast
30
30
from typing_extensions import TypedDict
31
31
from urllib3 .util .retry import Retry
32
32
60
60
from ._base import _build_properties_cache
61
61
from ._change_feed .change_feed_iterable import ChangeFeedIterable
62
62
from ._change_feed .change_feed_state import ChangeFeedState
63
+ from ._change_feed .feed_range_internal import FeedRangeInternalEpk
63
64
from ._constants import _Constants as Constants
64
65
from ._cosmos_http_logging_policy import CosmosHttpLoggingPolicy
65
66
from ._cosmos_responses import CosmosDict , CosmosList
71
72
from .partition_key import (
72
73
_Undefined ,
73
74
_Empty ,
74
- PartitionKey ,
75
+ _PartitionKeyKind ,
76
+ _PartitionKeyType ,
77
+ _SequentialPartitionKeyType ,
75
78
_return_undefined_or_empty_partition_key ,
76
- NonePartitionKeyValue ,
77
- _get_partition_key_from_partition_key_definition
78
79
)
79
80
80
- PartitionKeyType = Union [str , int , float , bool , Sequence [Union [str , int , float , bool , None ]], Type [NonePartitionKeyValue ]] # pylint: disable=line-too-long
81
-
82
-
83
81
class CredentialDict (TypedDict , total = False ):
84
82
masterKey : str
85
83
resourceTokens : Mapping [str , Any ]
@@ -1062,7 +1060,7 @@ def QueryItems(
1062
1060
database_or_container_link : str ,
1063
1061
query : Optional [Union [str , Dict [str , Any ]]],
1064
1062
options : Optional [Mapping [str , Any ]] = None ,
1065
- partition_key : Optional [PartitionKeyType ] = None ,
1063
+ partition_key : Optional [_PartitionKeyType ] = None ,
1066
1064
response_hook : Optional [Callable [[Mapping [str , Any ], Dict [str , Any ]], None ]] = None ,
1067
1065
** kwargs : Any
1068
1066
) -> ItemPaged [Dict [str , Any ]]:
@@ -3165,23 +3163,21 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
3165
3163
request_params = RequestObject (resource_type , documents ._OperationType .SqlQuery , req_headers )
3166
3164
request_params .set_excluded_location_from_options (options )
3167
3165
3168
- # check if query has prefix partition key
3169
- isPrefixPartitionQuery = kwargs .pop ("isPrefixPartitionQuery" , None )
3170
- if isPrefixPartitionQuery and "partitionKeyDefinition" in kwargs :
3166
+ # Check if the over lapping ranges can be populated
3167
+ feed_range_epk = None
3168
+ if "feed_range" in kwargs :
3169
+ feed_range = kwargs .pop ("feed_range" )
3170
+ feed_range_epk = FeedRangeInternalEpk .from_json (feed_range ).get_normalized_range ()
3171
+ elif "prefix_partition_key_object" in kwargs and "prefix_partition_key_value" in kwargs :
3172
+ prefix_partition_key_obj = kwargs .pop ("prefix_partition_key_object" )
3173
+ prefix_partition_key_value : _SequentialPartitionKeyType = kwargs .pop ("prefix_partition_key_value" )
3174
+ feed_range_epk = (
3175
+ prefix_partition_key_obj ._get_epk_range_for_prefix_partition_key (prefix_partition_key_value ))
3176
+
3177
+ # If feed_range_epk exist, query with the range
3178
+ if feed_range_epk is not None :
3171
3179
last_response_headers = CaseInsensitiveDict ()
3172
- # here get the over lapping ranges
3173
- # Default to empty Dictionary, but unlikely to be empty as we first check if we have it in kwargs
3174
- pk_properties : Union [PartitionKey , Dict ] = kwargs .pop ("partitionKeyDefinition" , {})
3175
- partition_key_definition = _get_partition_key_from_partition_key_definition (pk_properties )
3176
- partition_key_value : Sequence [
3177
- Union [None , bool , int , float , str , _Undefined , Type [NonePartitionKeyValue ]]] = cast (
3178
- Sequence [Union [None , bool , int , float , str , _Undefined , Type [NonePartitionKeyValue ]]],
3179
- pk_properties .get ("partition_key" )
3180
- )
3181
- feedrangeEPK = partition_key_definition ._get_epk_range_for_prefix_partition_key (
3182
- partition_key_value
3183
- ) # cspell:disable-line
3184
- over_lapping_ranges = self ._routing_map_provider .get_overlapping_ranges (resource_id , [feedrangeEPK ],
3180
+ over_lapping_ranges = self ._routing_map_provider .get_overlapping_ranges (resource_id , [feed_range_epk ],
3185
3181
options )
3186
3182
# It is possible to get more than one over lapping range. We need to get the query results for each one
3187
3183
results : Dict [str , Any ] = {}
@@ -3198,8 +3194,8 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
3198
3194
single_range = routing_range .Range .PartitionKeyRangeToRange (over_lapping_range )
3199
3195
# Since the range min and max are all Upper Cased string Hex Values,
3200
3196
# we can compare the values lexicographically
3201
- EPK_sub_range = routing_range .Range (range_min = max (single_range .min , feedrangeEPK .min ),
3202
- range_max = min (single_range .max , feedrangeEPK .max ),
3197
+ EPK_sub_range = routing_range .Range (range_min = max (single_range .min , feed_range_epk .min ),
3198
+ range_max = min (single_range .max , feed_range_epk .max ),
3203
3199
isMinInclusive = True , isMaxInclusive = False )
3204
3200
if single_range .min == EPK_sub_range .min and EPK_sub_range .max == single_range .max :
3205
3201
# The Epk Sub Range spans exactly one physical partition
@@ -3344,7 +3340,7 @@ def _ExtractPartitionKey(
3344
3340
partitionKeyDefinition : Mapping [str , Any ],
3345
3341
document : Mapping [str , Any ]
3346
3342
) -> Union [List [Optional [Union [str , float , bool ]]], str , float , bool , _Empty , _Undefined ]:
3347
- if partitionKeyDefinition ["kind" ] == "MultiHash" :
3343
+ if partitionKeyDefinition ["kind" ] == _PartitionKeyKind . MULTI_HASH :
3348
3344
ret : List [Optional [Union [str , float , bool ]]] = []
3349
3345
for partition_key_level in partitionKeyDefinition ["paths" ]:
3350
3346
# Parses the paths into a list of token each representing a property
0 commit comments