public async Task TestDistinct_CosmosElementContinuationTokenAsync() { async Task ImplemenationAsync(Container container, IReadOnlyList <CosmosObject> documents) { // Run the ordered distinct query through the continuation api, should result in the same set // since the previous hash is passed in the continuation token. foreach (string query in new string[] { "SELECT {0} VALUE c.age FROM c ORDER BY c.age", "SELECT {0} VALUE c.name FROM c ORDER BY c.name", "SELECT {0} VALUE c.name from c", "SELECT {0} VALUE c.age from c", "SELECT {0} VALUE c.mixedTypeField from c", "SELECT {0} TOP 2147483647 VALUE c.city from c", "SELECT {0} VALUE c.age from c ORDER BY c.name", }) { string queryWithoutDistinct = string.Format(query, ""); MockDistinctMap documentsSeen = new MockDistinctMap(); List <CosmosElement> documentsFromWithoutDistinct = await QueryTestsBase.RunQueryCombinationsAsync( container, queryWithoutDistinct, new QueryRequestOptions() { MaxConcurrency = 10, MaxItemCount = 100, }, QueryDrainingMode.HoldState | QueryDrainingMode.CosmosElementContinuationToken); documentsFromWithoutDistinct = documentsFromWithoutDistinct .Where(document => documentsSeen.Add(document, out UInt128 hash)) .ToList(); foreach (int pageSize in new int[] { 1, 10, 100 }) { string queryWithDistinct = string.Format(query, "DISTINCT"); List <CosmosElement> documentsFromWithDistinct = await QueryTestsBase.RunQueryCombinationsAsync( container, queryWithDistinct, new QueryRequestOptions() { MaxConcurrency = 10, MaxItemCount = pageSize }, QueryDrainingMode.HoldState | QueryDrainingMode.CosmosElementContinuationToken); Assert.AreEqual( expected: CosmosArray.Create(documentsFromWithDistinct), actual: CosmosArray.Create(documentsFromWithoutDistinct), message: $"Documents didn't match for {queryWithDistinct} on a Partitioned container"); } } } await this.TestQueryDistinctBaseAsync(ImplemenationAsync); }
public async Task TestPassthroughQueryAsync() { string[] inputDocs = new[] { @"{""id"":""documentId1"",""key"":""A"",""prop"":3,""shortArray"":[{""a"":5}]}", @"{""id"":""documentId2"",""key"":""A"",""prop"":2,""shortArray"":[{""a"":6}]}", @"{""id"":""documentId3"",""key"":""A"",""prop"":1,""shortArray"":[{""a"":7}]}", @"{""id"":""documentId4"",""key"":5,""prop"":3,""shortArray"":[{""a"":5}]}", @"{""id"":""documentId5"",""key"":5,""prop"":2,""shortArray"":[{""a"":6}]}", @"{""id"":""documentId6"",""key"":5,""prop"":1,""shortArray"":[{""a"":7}]}", @"{""id"":""documentId10"",""prop"":3,""shortArray"":[{""a"":5}]}", @"{""id"":""documentId11"",""prop"":2,""shortArray"":[{""a"":6}]}", @"{""id"":""documentId12"",""prop"":1,""shortArray"":[{""a"":7}]}", }; await this.CreateIngestQueryDeleteAsync( ConnectionModes.Direct, CollectionTypes.SinglePartition | CollectionTypes.MultiPartition, inputDocs, ImplementationAsync, "/key"); async Task ImplementationAsync(Container container, IReadOnlyList <CosmosObject> documents) { foreach (int maxDegreeOfParallelism in new int[] { 1, 100 }) { foreach (int maxItemCount in new int[] { 10, 100 }) { QueryRequestOptions feedOptions = new QueryRequestOptions { MaxBufferedItemCount = 7000, MaxConcurrency = maxDegreeOfParallelism, MaxItemCount = maxItemCount, }; foreach (string query in new string[] { "SELECT * FROM c WHERE c.key = 5", "SELECT * FROM c WHERE c.key = 5 ORDER BY c._ts", }) { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); List <CosmosElement> queryResults = await QueryTestsBase.RunQueryAsync( container, query, feedOptions); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Passthrough, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 3, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); string query = "SELECT TOP 2 c.id FROM c WHERE c.key = 5"; List <CosmosElement> queryResults = await QueryTestsBase.RunQueryAsync( container, query, feedOptions); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Passthrough, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 2, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); string query = "SELECT c.id FROM c WHERE c.key = 5 OFFSET 1 LIMIT 1"; List <CosmosElement> queryResults = await QueryTestsBase.RunQueryAsync( container, query, feedOptions); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Passthrough, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 1, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); string query = "SELECT VALUE COUNT(1) FROM c WHERE c.key = 5"; List <CosmosElement> queryResults = await QueryTestsBase.RunQueryAsync( container, query, feedOptions); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Specialized, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 1, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); Assert.AreEqual( 3, Number64.ToLong((queryResults.First() as CosmosNumber64).GetValue()), $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); string query = "SELECT VALUE c.key FROM c WHERE c.key = 5 GROUP BY c.key"; List <CosmosElement> queryResults = await QueryTestsBase.RunQueryCombinationsAsync( container, query, feedOptions, QueryDrainingMode.HoldState | QueryDrainingMode.CosmosElementContinuationToken); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Specialized, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 1, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } { feedOptions.TestSettings = new TestInjections(simulate429s: false, simulateEmptyPages: false, responseStats: new TestInjections.ResponseStats()); string query = "SELECT DISTINCT VALUE c.key FROM c WHERE c.key = 5"; List <CosmosElement> queryResults = await QueryTestsBase.RunQueryCombinationsAsync( container, query, feedOptions, QueryDrainingMode.HoldState | QueryDrainingMode.CosmosElementContinuationToken); Assert.IsTrue(feedOptions.TestSettings.Stats.PipelineType.HasValue); Assert.AreEqual(TestInjections.PipelineType.Specialized, feedOptions.TestSettings.Stats.PipelineType.Value); Assert.AreEqual( 1, queryResults.Count, $"query: {query} failed with {nameof(maxDegreeOfParallelism)}: {maxDegreeOfParallelism}, {nameof(maxItemCount)}: {maxItemCount}"); } } } } }