2626import os
2727import urllib .parse
2828import 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
3030from typing_extensions import TypedDict
3131from urllib3 .util .retry import Retry
3232
6060from ._base import _build_properties_cache
6161from ._change_feed .change_feed_iterable import ChangeFeedIterable
6262from ._change_feed .change_feed_state import ChangeFeedState
63+ from ._change_feed .feed_range_internal import FeedRangeInternalEpk
6364from ._constants import _Constants as Constants
6465from ._cosmos_http_logging_policy import CosmosHttpLoggingPolicy
6566from ._cosmos_responses import CosmosDict , CosmosList
7172from .partition_key import (
7273 _Undefined ,
7374 _Empty ,
74- PartitionKey ,
75+ _PartitionKeyKind ,
76+ _PartitionKeyType ,
77+ _SequentialPartitionKeyType ,
7578 _return_undefined_or_empty_partition_key ,
76- NonePartitionKeyValue ,
77- _get_partition_key_from_partition_key_definition
7879)
7980
80- PartitionKeyType = Union [str , int , float , bool , Sequence [Union [str , int , float , bool , None ]], Type [NonePartitionKeyValue ]] # pylint: disable=line-too-long
81-
82-
8381class CredentialDict (TypedDict , total = False ):
8482 masterKey : str
8583 resourceTokens : Mapping [str , Any ]
@@ -1062,7 +1060,7 @@ def QueryItems(
10621060 database_or_container_link : str ,
10631061 query : Optional [Union [str , Dict [str , Any ]]],
10641062 options : Optional [Mapping [str , Any ]] = None ,
1065- partition_key : Optional [PartitionKeyType ] = None ,
1063+ partition_key : Optional [_PartitionKeyType ] = None ,
10661064 response_hook : Optional [Callable [[Mapping [str , Any ], Dict [str , Any ]], None ]] = None ,
10671065 ** kwargs : Any
10681066 ) -> ItemPaged [Dict [str , Any ]]:
@@ -3165,23 +3163,21 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
31653163 request_params = RequestObject (resource_type , documents ._OperationType .SqlQuery , req_headers )
31663164 request_params .set_excluded_location_from_options (options )
31673165
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 :
31713179 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 ],
31853181 options )
31863182 # It is possible to get more than one over lapping range. We need to get the query results for each one
31873183 results : Dict [str , Any ] = {}
@@ -3198,8 +3194,8 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
31983194 single_range = routing_range .Range .PartitionKeyRangeToRange (over_lapping_range )
31993195 # Since the range min and max are all Upper Cased string Hex Values,
32003196 # 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 ),
32033199 isMinInclusive = True , isMaxInclusive = False )
32043200 if single_range .min == EPK_sub_range .min and EPK_sub_range .max == single_range .max :
32053201 # The Epk Sub Range spans exactly one physical partition
@@ -3344,7 +3340,7 @@ def _ExtractPartitionKey(
33443340 partitionKeyDefinition : Mapping [str , Any ],
33453341 document : Mapping [str , Any ]
33463342 ) -> Union [List [Optional [Union [str , float , bool ]]], str , float , bool , _Empty , _Undefined ]:
3347- if partitionKeyDefinition ["kind" ] == "MultiHash" :
3343+ if partitionKeyDefinition ["kind" ] == _PartitionKeyKind . MULTI_HASH :
33483344 ret : List [Optional [Union [str , float , bool ]]] = []
33493345 for partition_key_level in partitionKeyDefinition ["paths" ]:
33503346 # Parses the paths into a list of token each representing a property
0 commit comments