@@ -35,9 +35,12 @@ public void TestQueriesOnSplitContainer()
35
35
{
36
36
List < SubpartitionTestInput > inputs = new List < SubpartitionTestInput >
37
37
{
38
- new SubpartitionTestInput ( "SELECT" , query : @"SELECT c.id, c.value2 FROM c" , ode : true ) ,
39
- new SubpartitionTestInput ( "SELECT without ODE" , query : @"SELECT c.id, c.value2 FROM c" , ode : false ) ,
38
+ new SubpartitionTestInput ( description : "SELECT" , query : @"SELECT c.id, c.value2 FROM c" , ode : true ) ,
39
+ new SubpartitionTestInput ( description : "SELECT without ODE" , query : @"SELECT c.id, c.value2 FROM c" , ode : false ) ,
40
+ new SubpartitionTestInput ( description : "SELECT ORDER BY with ODE" , query : @"SELECT c.id, c.value2, c.intVal FROM c ORDER BY c.intVal" , ode : true , sortResults : false ) ,
41
+ new SubpartitionTestInput ( description : "SELECT ORDER BY without ODE" , query : @"SELECT c.id, c.value2, c.intVal FROM c ORDER BY c.intVal" , ode : false , sortResults : false ) ,
40
42
} ;
43
+
41
44
this . ExecuteTestSuite ( inputs ) ;
42
45
}
43
46
@@ -65,16 +68,19 @@ public async Task VerifyTestFrameworkSupportsPartitionSplit()
65
68
66
69
public override SubpartitionTestOutput ExecuteTest ( SubpartitionTestInput input )
67
70
{
68
- IMonadicDocumentContainer monadicDocumentContainer = CreateSplitDocumentContainerAsync ( DocumentCount ) . Result ;
71
+ QueryRequestOptions queryRequestOptions = new QueryRequestOptions ( )
72
+ {
73
+ PartitionKey = new PartitionKeyBuilder ( ) . Add ( SplitPartitionKey . ToString ( ) ) . Build ( )
74
+ } ;
75
+
76
+ IMonadicDocumentContainer monadicDocumentContainer = CreateSplitDocumentContainerAsync ( DocumentCount , queryRequestOptions ) . Result ;
69
77
DocumentContainer documentContainer = new DocumentContainer ( monadicDocumentContainer ) ;
78
+ TryCatch _ = monadicDocumentContainer . MonadicRefreshProviderAsync ( NoOpTrace . Singleton , cancellationToken : default ) . Result ;
79
+ List < FeedRangeEpk > containerRanges = documentContainer . GetFeedRangesAsync ( NoOpTrace . Singleton , cancellationToken : default ) . Result ;
70
80
71
81
List < CosmosElement > documents = new List < CosmosElement > ( ) ;
72
- QueryRequestOptions queryRequestOptions = new QueryRequestOptions ( )
73
- {
74
- PartitionKey = new PartitionKeyBuilder ( ) . Add ( SplitPartitionKey . ToString ( ) ) . Build ( )
75
- } ;
76
82
( CosmosQueryExecutionContextFactory . InputParameters inputParameters , CosmosQueryContextCore cosmosQueryContextCore ) =
77
- CreateInputParamsAndQueryContext ( input , queryRequestOptions ) ;
83
+ CreateInputParamsAndQueryContext ( input , queryRequestOptions , containerRanges ) ;
78
84
IQueryPipelineStage queryPipelineStage = CosmosQueryExecutionContextFactory . Create (
79
85
documentContainer ,
80
86
cosmosQueryContextCore ,
@@ -92,10 +98,10 @@ public override SubpartitionTestOutput ExecuteTest(SubpartitionTestInput input)
92
98
documents . AddRange ( tryGetPage . Result . Documents ) ;
93
99
}
94
100
95
- return new SubpartitionTestOutput ( documents ) ;
101
+ return new SubpartitionTestOutput ( documents , input . SortResults ) ;
96
102
}
97
103
98
- private static Tuple < CosmosQueryExecutionContextFactory . InputParameters , CosmosQueryContextCore > CreateInputParamsAndQueryContext ( SubpartitionTestInput input , QueryRequestOptions queryRequestOptions )
104
+ private static Tuple < CosmosQueryExecutionContextFactory . InputParameters , CosmosQueryContextCore > CreateInputParamsAndQueryContext ( SubpartitionTestInput input , QueryRequestOptions queryRequestOptions , IReadOnlyList < FeedRangeEpk > containerRanges )
99
105
{
100
106
string query = input . Query ;
101
107
CosmosElement continuationToken = null ;
@@ -134,10 +140,20 @@ public override SubpartitionTestOutput ExecuteTest(SubpartitionTestInput input)
134
140
isNonStreamingOrderByQueryFeatureDisabled : queryRequestOptions . IsNonStreamingOrderByQueryFeatureDisabled ,
135
141
testInjections : queryRequestOptions . TestSettings ) ;
136
142
143
+ List < PartitionKeyRange > targetPkRanges = new ( ) ;
144
+ foreach ( FeedRangeEpk feedRangeEpk in containerRanges )
145
+ {
146
+ targetPkRanges . Add ( new PartitionKeyRange
147
+ {
148
+ MinInclusive = feedRangeEpk . Range . Min ,
149
+ MaxExclusive = feedRangeEpk . Range . Max ,
150
+ } ) ;
151
+ }
152
+
137
153
string databaseId = "db1234" ;
138
154
string resourceLink = $ "dbs/{ databaseId } /colls";
139
155
CosmosQueryContextCore cosmosQueryContextCore = new CosmosQueryContextCore (
140
- client : new TestCosmosQueryClient ( queryPartitionProvider ) ,
156
+ client : new TestCosmosQueryClient ( queryPartitionProvider , targetPkRanges ) ,
141
157
resourceTypeEnum : Documents . ResourceType . Document ,
142
158
operationType : Documents . OperationType . Query ,
143
159
resourceType : typeof ( QueryResponseCore ) ,
@@ -215,20 +231,20 @@ internal static PartitionKeyDefinition CreatePartitionKeyDefinition()
215
231
return partitionKeyDefinition ;
216
232
}
217
233
218
- private static async Task < IDocumentContainer > CreateSplitDocumentContainerAsync ( int numItems )
234
+ private static async Task < IDocumentContainer > CreateSplitDocumentContainerAsync ( int numItems , QueryRequestOptions queryRequestOptions )
219
235
{
220
236
PartitionKeyDefinition partitionKeyDefinition = CreatePartitionKeyDefinition ( ) ;
221
- InMemoryContainer inMemoryContainer = await CreateSplitInMemoryDocumentContainerAsync ( numItems , partitionKeyDefinition ) ;
237
+ InMemoryContainer inMemoryContainer = await CreateSplitInMemoryDocumentContainerAsync ( numItems , partitionKeyDefinition , queryRequestOptions ) ;
222
238
DocumentContainer documentContainer = new DocumentContainer ( inMemoryContainer ) ;
223
239
return documentContainer ;
224
240
}
225
241
226
- private static async Task < InMemoryContainer > CreateSplitInMemoryDocumentContainerAsync ( int numItems , PartitionKeyDefinition partitionKeyDefinition )
242
+ private static async Task < InMemoryContainer > CreateSplitInMemoryDocumentContainerAsync ( int numItems , PartitionKeyDefinition partitionKeyDefinition , QueryRequestOptions queryRequestOptions = null )
227
243
{
228
- InMemoryContainer inMemoryContainer = new InMemoryContainer ( partitionKeyDefinition , createSplitForMultiHashAtSecondlevel : true , resolvePartitionsBasedOnPrefix : true ) ;
244
+ InMemoryContainer inMemoryContainer = new InMemoryContainer ( partitionKeyDefinition , createSplitForMultiHashAtSecondlevel : true , resolvePartitionsBasedOnPrefix : true , queryRequestOptions : queryRequestOptions ) ;
229
245
for ( int i = 0 ; i < numItems ; i ++ )
230
246
{
231
- CosmosObject item = CosmosObject . Parse ( $ "{{\" id\" : \" { i % 5 } \" , \" value1\" : \" { Guid . NewGuid ( ) } \" , \" value2\" : \" { i } \" }}") ;
247
+ CosmosObject item = CosmosObject . Parse ( $ "{{\" id\" : \" { i % 5 } \" , \" value1\" : \" { Guid . NewGuid ( ) } \" , \" value2\" : \" { i } \" , \" intVal \" : { ( numItems / 2 ) - i } }}") ;
232
248
while ( true )
233
249
{
234
250
TryCatch < Record > monadicCreateRecord = await inMemoryContainer . MonadicCreateItemAsync ( item , cancellationToken : default ) ;
@@ -243,13 +259,16 @@ private static async Task<InMemoryContainer> CreateSplitInMemoryDocumentContaine
243
259
244
260
return inMemoryContainer ;
245
261
}
262
+
246
263
internal class TestCosmosQueryClient : CosmosQueryClient
247
264
{
248
265
private readonly QueryPartitionProvider queryPartitionProvider ;
266
+ private readonly IReadOnlyList < PartitionKeyRange > targetPartitionKeyRanges ;
249
267
250
- public TestCosmosQueryClient ( QueryPartitionProvider queryPartitionProvider )
268
+ public TestCosmosQueryClient ( QueryPartitionProvider queryPartitionProvider , IEnumerable < PartitionKeyRange > targetPartitionKeyRanges )
251
269
{
252
270
this . queryPartitionProvider = queryPartitionProvider ;
271
+ this . targetPartitionKeyRanges = targetPartitionKeyRanges . ToList ( ) ;
253
272
}
254
273
255
274
public override Action < IQueryable > OnExecuteScalarQueryCallback => throw new NotImplementedException ( ) ;
@@ -322,14 +341,7 @@ public override Task<List<PartitionKeyRange>> GetTargetPartitionKeyRangeByFeedRa
322
341
323
342
public override Task < List < PartitionKeyRange > > GetTargetPartitionKeyRangesAsync ( string resourceLink , string collectionResourceId , IReadOnlyList < Documents . Routing . Range < string > > providedRanges , bool forceRefresh , ITrace trace )
324
343
{
325
- return Task . FromResult ( new List < PartitionKeyRange >
326
- {
327
- new PartitionKeyRange ( )
328
- {
329
- MinInclusive = Documents . Routing . PartitionKeyInternal . MinimumInclusiveEffectivePartitionKey ,
330
- MaxExclusive = Documents . Routing . PartitionKeyInternal . MaximumExclusiveEffectivePartitionKey
331
- }
332
- } ) ;
344
+ return Task . FromResult ( this . targetPartitionKeyRanges . ToList ( ) ) ;
333
345
}
334
346
335
347
public override Task < IReadOnlyList < PartitionKeyRange > > TryGetOverlappingRangesAsync ( string collectionResourceId , Documents . Routing . Range < string > range , bool forceRefresh = false )
@@ -351,17 +363,20 @@ public override async Task<TryCatch<PartitionedQueryExecutionInfo>> TryGetPartit
351
363
352
364
public class SubpartitionTestInput : BaselineTestInput
353
365
{
354
- public SubpartitionTestInput ( string description , string query , bool ode )
366
+ public SubpartitionTestInput ( string description , string query , bool ode , bool sortResults = true )
355
367
: base ( description )
356
368
{
357
369
this . Query = query ;
358
370
this . ODE = ode ;
371
+ this . SortResults = sortResults ;
359
372
}
360
373
361
374
internal string Query { get ; }
362
375
363
376
internal bool ODE { get ; }
364
377
378
+ internal bool SortResults { get ; }
379
+
365
380
public override void SerializeAsXml ( XmlWriter xmlWriter )
366
381
{
367
382
xmlWriter . WriteElementString ( "Description" , this . Description ) ;
@@ -375,17 +390,25 @@ public override void SerializeAsXml(XmlWriter xmlWriter)
375
390
public class SubpartitionTestOutput : BaselineTestOutput
376
391
{
377
392
private readonly List < CosmosElement > documents ;
393
+ private readonly bool sortResults ;
378
394
379
- internal SubpartitionTestOutput ( IReadOnlyList < CosmosElement > documents )
395
+ internal SubpartitionTestOutput ( IReadOnlyList < CosmosElement > documents , bool sortResults )
380
396
{
381
397
this . documents = documents . ToList ( ) ;
398
+ this . sortResults = sortResults ;
382
399
}
383
400
384
401
public override void SerializeAsXml ( XmlWriter xmlWriter )
385
402
{
386
403
xmlWriter . WriteStartElement ( "Documents" ) ;
387
- string content = string . Join ( $ ",{ Environment . NewLine } ",
388
- this . documents . Select ( doc => doc . ToString ( ) ) . OrderBy ( serializedDoc => serializedDoc ) ) ;
404
+
405
+ IEnumerable < string > lines = this . documents . Select ( doc => doc . ToString ( ) ) ;
406
+ if ( this . sortResults )
407
+ {
408
+ lines = lines . OrderBy ( serializedDoc => serializedDoc ) ;
409
+ }
410
+
411
+ string content = string . Join ( $ ",{ Environment . NewLine } ", lines ) ;
389
412
xmlWriter . WriteCData ( content ) ;
390
413
xmlWriter . WriteEndElement ( ) ;
391
414
}
0 commit comments