@@ -9,6 +9,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.ExecutionContext
99 using System . Linq ;
1010 using System . Threading ;
1111 using System . Threading . Tasks ;
12+ using global ::Azure ;
1213 using Microsoft . Azure . Cosmos ;
1314 using Microsoft . Azure . Cosmos . CosmosElements ;
1415 using Microsoft . Azure . Cosmos . Pagination ;
@@ -27,6 +28,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.ExecutionContext
2728 using Microsoft . Azure . Cosmos . SqlObjects ;
2829 using Microsoft . Azure . Cosmos . SqlObjects . Visitors ;
2930 using Microsoft . Azure . Cosmos . Tracing ;
31+ using Microsoft . Azure . Documents . Routing ;
3032
3133 internal static class CosmosQueryExecutionContextFactory
3234 {
@@ -211,10 +213,10 @@ private static async Task<TryCatch<IQueryPipelineStage>> TryCreateCoreContextAsy
211213
212214 // Only thing that matters is that we target the correct range.
213215 Documents . PartitionKeyDefinition partitionKeyDefinition = GetPartitionKeyDefinition ( inputParameters , containerQueryProperties ) ;
214- List < Documents . PartitionKeyRange > targetRanges = await cosmosQueryContext . QueryClient . GetTargetPartitionKeyRangesByEpkStringAsync (
216+ List < Documents . PartitionKeyRange > targetRanges = await cosmosQueryContext . QueryClient . GetTargetPartitionKeyRangesAsync (
215217 cosmosQueryContext . ResourceLink ,
216218 containerQueryProperties . ResourceId ,
217- containerQueryProperties . EffectivePartitionKeyString ,
219+ containerQueryProperties . EffectiveRangesForPartitionKey ,
218220 forceRefresh : false ,
219221 createQueryPipelineTrace ) ;
220222
@@ -635,67 +637,54 @@ private static async Task<PartitionedQueryExecutionInfo> GetPartitionedQueryExec
635637 ITrace trace )
636638 {
637639 List < Documents . PartitionKeyRange > targetRanges ;
638- if ( containerQueryProperties . EffectivePartitionKeyString != null )
640+ if ( containerQueryProperties . EffectiveRangesForPartitionKey != null )
639641 {
640- targetRanges = await queryClient . GetTargetPartitionKeyRangesByEpkStringAsync (
642+ targetRanges = await queryClient . GetTargetPartitionKeyRangesAsync (
641643 resourceLink ,
642644 containerQueryProperties . ResourceId ,
643- containerQueryProperties . EffectivePartitionKeyString ,
645+ containerQueryProperties . EffectiveRangesForPartitionKey ,
644646 forceRefresh : false ,
645647 trace ) ;
646648 }
647649 else if ( TryGetEpkProperty ( properties , out string effectivePartitionKeyString ) )
648650 {
649- targetRanges = await queryClient . GetTargetPartitionKeyRangesByEpkStringAsync (
651+ //Note that here we have no way to consume the EPK string as there is no way to convert
652+ //the string to the partition key type to evaulate the number of components which needs to be done for the
653+ //multihahs methods/classes. This is particually important for queries with prefix partition key.
654+ //the EPK sting header is only for internal use but this needs to be fixed in the future.
655+ List < Range < string > > effectiveRanges = new List < Range < string > >
656+ { Range < string > . GetPointRange ( effectivePartitionKeyString ) } ;
657+
658+ targetRanges = await queryClient . GetTargetPartitionKeyRangesAsync (
650659 resourceLink ,
651660 containerQueryProperties . ResourceId ,
652- effectivePartitionKeyString ,
661+ effectiveRanges ,
653662 forceRefresh : false ,
654663 trace ) ;
655664 }
656665 else if ( feedRangeInternal != null )
657666 {
658667 targetRanges = await queryClient . GetTargetPartitionKeyRangeByFeedRangeAsync (
659- resourceLink ,
660- containerQueryProperties . ResourceId ,
661- containerQueryProperties . PartitionKeyDefinition ,
662- feedRangeInternal ,
663- forceRefresh : false ,
664- trace ) ;
668+ resourceLink ,
669+ containerQueryProperties . ResourceId ,
670+ containerQueryProperties . PartitionKeyDefinition ,
671+ feedRangeInternal ,
672+ forceRefresh : false ,
673+ trace ) ;
665674 }
666675 else
667676 {
668- targetRanges = await queryClient . GetTargetPartitionKeyRangesAsync (
669- resourceLink ,
670- containerQueryProperties . ResourceId ,
671- partitionedQueryExecutionInfo . QueryRanges ,
672- forceRefresh : false ,
673- trace ) ;
677+ targetRanges = await queryClient . GetTargetPartitionKeyRangesAsync (
678+ resourceLink ,
679+ containerQueryProperties . ResourceId ,
680+ partitionedQueryExecutionInfo . QueryRanges ,
681+ forceRefresh : false ,
682+ trace ) ;
674683 }
675684
676685 return targetRanges ;
677686 }
678687
679- private static void SetTestInjectionPipelineType ( InputParameters inputParameters , string pipelineType )
680- {
681- TestInjections . ResponseStats responseStats = inputParameters ? . TestInjections ? . Stats ;
682- if ( responseStats != null )
683- {
684- if ( pipelineType == OptimisticDirectExecution )
685- {
686- responseStats . PipelineType = TestInjections . PipelineType . OptimisticDirectExecution ;
687- }
688- else if ( pipelineType == Specialized )
689- {
690- responseStats . PipelineType = TestInjections . PipelineType . Specialized ;
691- }
692- else
693- {
694- responseStats . PipelineType = TestInjections . PipelineType . Passthrough ;
695- }
696- }
697- }
698-
699688 private static bool TryGetEpkProperty (
700689 IReadOnlyDictionary < string , object > properties ,
701690 out string effectivePartitionKeyString )
@@ -718,6 +707,26 @@ private static bool TryGetEpkProperty(
718707 return false ;
719708 }
720709
710+ private static void SetTestInjectionPipelineType ( InputParameters inputParameters , string pipelineType )
711+ {
712+ TestInjections . ResponseStats responseStats = inputParameters ? . TestInjections ? . Stats ;
713+ if ( responseStats != null )
714+ {
715+ if ( pipelineType == OptimisticDirectExecution )
716+ {
717+ responseStats . PipelineType = TestInjections . PipelineType . OptimisticDirectExecution ;
718+ }
719+ else if ( pipelineType == Specialized )
720+ {
721+ responseStats . PipelineType = TestInjections . PipelineType . Specialized ;
722+ }
723+ else
724+ {
725+ responseStats . PipelineType = TestInjections . PipelineType . Passthrough ;
726+ }
727+ }
728+ }
729+
721730 private static Documents . PartitionKeyDefinition GetPartitionKeyDefinition ( InputParameters inputParameters , ContainerQueryProperties containerQueryProperties )
722731 {
723732 //todo:elasticcollections this may rely on information from collection cache which is outdated
@@ -781,14 +790,13 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
781790 else
782791 {
783792 Documents . PartitionKeyDefinition partitionKeyDefinition = GetPartitionKeyDefinition ( inputParameters , containerQueryProperties ) ;
784- if ( inputParameters . PartitionKey != null )
793+ if ( inputParameters . PartitionKey . HasValue )
785794 {
786795 Debug . Assert ( partitionKeyDefinition != null , "CosmosQueryExecutionContextFactory Assert!" , "PartitionKeyDefinition cannot be null if partitionKey is defined" ) ;
787-
788- targetRanges = await cosmosQueryContext . QueryClient . GetTargetPartitionKeyRangesByEpkStringAsync (
796+ targetRanges = await cosmosQueryContext . QueryClient . GetTargetPartitionKeyRangesAsync (
789797 cosmosQueryContext . ResourceLink ,
790798 containerQueryProperties . ResourceId ,
791- containerQueryProperties . EffectivePartitionKeyString ,
799+ containerQueryProperties . EffectiveRangesForPartitionKey ,
792800 forceRefresh : false ,
793801 trace ) ;
794802 }
0 commit comments