diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/PipelineFactory.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/PipelineFactory.cs index 3273cc52b1..7a447f0e0b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/PipelineFactory.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/PipelineFactory.cs @@ -108,19 +108,27 @@ public static TryCatch MonadicCreate( maxConcurrency: maxConcurrency); if (hybridSearchQueryInfo.Skip != null) - { + { + Debug.Assert(hybridSearchQueryInfo.Skip.Value <= int.MaxValue, "PipelineFactory Assert!", "Skip value must be <= int.MaxValue"); + + int skipCount = (int)hybridSearchQueryInfo.Skip.Value; + MonadicCreatePipelineStage monadicCreateSourceStage = monadicCreatePipelineStage; monadicCreatePipelineStage = (continuationToken) => SkipQueryPipelineStage.MonadicCreate( - hybridSearchQueryInfo.Skip.Value, + skipCount, continuationToken, monadicCreateSourceStage); } if (hybridSearchQueryInfo.Take != null) - { + { + Debug.Assert(hybridSearchQueryInfo.Take.Value <= int.MaxValue, "PipelineFactory Assert!", "Take value must be <= int.MaxValue"); + + int takeCount = (int)hybridSearchQueryInfo.Take.Value; + MonadicCreatePipelineStage monadicCreateSourceStage = monadicCreatePipelineStage; monadicCreatePipelineStage = (continuationToken) => TakeQueryPipelineStage.MonadicCreateLimitStage( - hybridSearchQueryInfo.Take.Value, + takeCount, requestContinuationToken, monadicCreateSourceStage); } @@ -150,7 +158,7 @@ public static TryCatch MonadicCreate( long optimalPageSize = maxItemCount; if (queryInfo.HasOrderBy) { - int top; + uint top; if (queryInfo.HasTop && (queryInfo.Top.Value > 0)) { top = queryInfo.Top.Value; @@ -162,6 +170,11 @@ public static TryCatch MonadicCreate( else { top = 0; + } + + if (top > int.MaxValue) + { + throw new ArgumentOutOfRangeException(nameof(queryInfo.Top.Value)); } if (top > 0) @@ -257,27 +270,39 @@ public static TryCatch MonadicCreate( if (queryInfo.HasOffset) { + Debug.Assert(queryInfo.Offset.Value <= int.MaxValue, "PipelineFactory Assert!", "Offset value must be <= int.MaxValue"); + + int offsetCount = (int)queryInfo.Offset.Value; + MonadicCreatePipelineStage monadicCreateSourceStage = monadicCreatePipelineStage; monadicCreatePipelineStage = (continuationToken) => SkipQueryPipelineStage.MonadicCreate( - queryInfo.Offset.Value, + offsetCount, continuationToken, monadicCreateSourceStage); } if (queryInfo.HasLimit) { + Debug.Assert(queryInfo.Limit.Value <= int.MaxValue, "PipelineFactory Assert!", "Limit value must be <= int.MaxValue"); + + int limitCount = (int)queryInfo.Limit.Value; + MonadicCreatePipelineStage monadicCreateSourceStage = monadicCreatePipelineStage; monadicCreatePipelineStage = (continuationToken) => TakeQueryPipelineStage.MonadicCreateLimitStage( - queryInfo.Limit.Value, + limitCount, continuationToken, monadicCreateSourceStage); } if (queryInfo.HasTop) { + Debug.Assert(queryInfo.Top.Value <= int.MaxValue, "PipelineFactory Assert!", "Top value must be <= int.MaxValue"); + + int topCount = (int)queryInfo.Top.Value; + MonadicCreatePipelineStage monadicCreateSourceStage = monadicCreatePipelineStage; monadicCreatePipelineStage = (continuationToken) => TakeQueryPipelineStage.MonadicCreateTopStage( - queryInfo.Top.Value, + topCount, continuationToken, monadicCreateSourceStage); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.Client.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.Client.cs index f23744e96c..ce1cab537b 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.Client.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.Client.cs @@ -5,7 +5,8 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.Skip { using System; - using System.Collections.Generic; + using System.Collections.Generic; + using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -32,7 +33,7 @@ private ClientSkipQueryPipelineStage( int offsetCount, CosmosElement continuationToken, MonadicCreatePipelineStage monadicCreatePipelineStage) - { + { if (monadicCreatePipelineStage == null) { throw new ArgumentNullException(nameof(monadicCreatePipelineStage)); @@ -120,7 +121,9 @@ public override async ValueTask MoveNextAsync(ITrace trace, CancellationTo IReadOnlyList documentsAfterSkip = sourcePage.Documents.Skip(this.skipCount).ToList(); int numberOfDocumentsSkipped = sourcePage.Documents.Count - documentsAfterSkip.Count; - this.skipCount -= numberOfDocumentsSkipped; + this.skipCount -= numberOfDocumentsSkipped; + + Debug.Assert(this.skipCount >= 0, $"{nameof(SkipQueryPipelineStage)} Assert!", "this.skipCount should be greater than or equal to 0"); QueryState state; if ((sourcePage.State != null) && (sourcePage.DisallowContinuationTokenMessage == null)) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.cs index d1ce26079b..d4319a44b2 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Skip/SkipQueryPipelineStage.cs @@ -22,7 +22,7 @@ protected SkipQueryPipelineStage( long skipCount) : base(source) { - if (skipCount > int.MaxValue) + if (skipCount > int.MaxValue || skipCount < 0) { throw new ArgumentOutOfRangeException(nameof(skipCount)); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.Client.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.Client.cs index 712642e95a..37edffc3f0 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.Client.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.Client.cs @@ -38,7 +38,7 @@ private ClientTakeQueryPipelineStage( { if (limitCount < 0) { - throw new ArgumentException($"{nameof(limitCount)}: {limitCount} must be a non negative number."); + throw new ArgumentException($"{nameof(limitCount)}: {limitCount} must be a non negative number."); } if (monadicCreatePipelineStage == null) @@ -256,7 +256,7 @@ private sealed class LimitContinuationToken : TakeContinuationToken /// The limit to the number of document drained for the remainder of the query. /// The continuation token for the source component of the query. public LimitContinuationToken(int limit, string sourceToken) - { + { if (limit < 0) { throw new ArgumentException($"{nameof(limit)} must be a non negative number."); @@ -330,7 +330,7 @@ private sealed class TopContinuationToken : TakeContinuationToken /// The limit to the number of document drained for the remainder of the query. /// The continuation token for the source component of the query. public TopContinuationToken(int top, string sourceToken) - { + { this.Top = top; this.SourceToken = sourceToken; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.cs index ab37bfe4a6..32f8cb2eb1 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Take/TakeQueryPipelineStage.cs @@ -19,7 +19,7 @@ protected TakeQueryPipelineStage( IQueryPipelineStage source, int takeCount) : base(source) - { + { this.takeCount = takeCount; } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/HybridSearchQueryInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/HybridSearchQueryInfo.cs index 1a491243e7..bfd2c44e07 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/HybridSearchQueryInfo.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/HybridSearchQueryInfo.cs @@ -38,14 +38,14 @@ public QueryInfo ProjectionQueryInfo } [JsonProperty("skip")] - public int? Skip + public uint? Skip { get; set; } [JsonProperty("take")] - public int? Take + public uint? Take { get; set; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryInfo.cs index fa796a4965..bc9c21a522 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryInfo.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryInfo.cs @@ -24,21 +24,21 @@ public DistinctQueryType DistinctType } [JsonProperty("top")] - public int? Top + public uint? Top { get; set; } [JsonProperty("offset")] - public int? Offset + public uint? Offset { get; set; } [JsonProperty("limit")] - public int? Limit + public uint? Limit { get; set; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs index d84301b4d7..e5f4a381b9 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs @@ -318,9 +318,56 @@ internal TryCatch TryGetPartitionedQueryE { DateParseHandling = DateParseHandling.None, MaxDepth = 64, // https://github.com/advisories/GHSA-5crp-9r3c-p9vr - }); + }); + + if (!this.ValidateQueryExecutionInfo(queryInfoInternal, out ArgumentException innerException)) + { + return TryCatch.FromException( + new ExpectedQueryPartitionProviderException( + serializedQueryExecutionInfo, + innerException)); + } return TryCatch.FromResult(queryInfoInternal); + } + + private bool ValidateQueryExecutionInfo(PartitionedQueryExecutionInfoInternal queryExecutionInfo, out ArgumentException innerException) + { + if (queryExecutionInfo.QueryInfo?.Limit.HasValue == true && + queryExecutionInfo.QueryInfo.Limit.Value > int.MaxValue) + { + innerException = new ArgumentOutOfRangeException("QueryInfo.Limit"); + return false; + } + + if (queryExecutionInfo.QueryInfo?.Offset.HasValue == true && + queryExecutionInfo.QueryInfo.Offset.Value > int.MaxValue) + { + innerException = new ArgumentOutOfRangeException("QueryInfo.Offset"); + return false; + } + + if (queryExecutionInfo.QueryInfo?.Top.HasValue == true && + queryExecutionInfo.QueryInfo.Top.Value > int.MaxValue) + { + innerException = new ArgumentOutOfRangeException("QueryInfo.Top"); + return false; + } + + if ((queryExecutionInfo.HybridSearchQueryInfo?.Skip ?? 0) > int.MaxValue) + { + innerException = new ArgumentOutOfRangeException("HybridSearchQueryInfo.Skip"); + return false; + } + + if ((queryExecutionInfo.HybridSearchQueryInfo?.Take ?? 0) > int.MaxValue) + { + innerException = new ArgumentOutOfRangeException("HybridSearchQueryInfo.Take"); + return false; + } + + innerException = null; + return true; } internal static TryCatch TryCreateServiceProvider(string queryEngineConfiguration) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NegativeQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NegativeQueryTests.cs index dc48426ea2..c9deb491f5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NegativeQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NegativeQueryTests.cs @@ -101,5 +101,47 @@ await this.CreateIngestQueryDeleteAsync( QueryTestsBase.NoDocuments, ImplementationAsync); } + + [TestMethod] + public async Task TestTopOffsetLimitClientRanges() + { + async Task ImplementationAsync(Container container, IReadOnlyList documents) + { + await QueryTestsBase.NoOp(); + + foreach((string parameterName, string query) in new[] + { + ("QueryInfo.Offset", "SELECT c.name FROM c OFFSET 2147483648 LIMIT 10"), + ("QueryInfo.Limit", "SELECT c.name FROM c OFFSET 10 LIMIT 2147483648"), + ("QueryInfo.Top", "SELECT TOP 2147483648 c.name FROM c"), + }) + try + { + List expectedValues = new List(); + FeedIterator resultSetIterator = container.GetItemQueryIterator( + query, + requestOptions: new QueryRequestOptions() { MaxConcurrency = 0 }); + + while (resultSetIterator.HasMoreResults) + { + expectedValues.AddRange(await resultSetIterator.ReadNextAsync()); + } + + Assert.Fail("Expected to get an exception for this query."); + } + catch (CosmosException e) + { + Assert.IsTrue(e.StatusCode == HttpStatusCode.BadRequest); + Assert.IsTrue(e.InnerException?.InnerException is ArgumentException ex && + ex.Message.Contains(parameterName)); + } + } + + await this.CreateIngestQueryDeleteAsync( + ConnectionModes.Direct | ConnectionModes.Gateway, + CollectionTypes.MultiPartition, + QueryTestsBase.NoDocuments, + ImplementationAsync); + } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SkipTakeQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SkipTakeQueryTests.cs index ad52611484..f4e9ddf2fe 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SkipTakeQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/SkipTakeQueryTests.cs @@ -185,5 +185,43 @@ ORDER BY c.guid } } } + + [TestMethod] + public async Task TestTopOffsetLimitClientRanges() + { + async Task ImplementationAsync(Container container, IReadOnlyList documents) + { + await QueryTestsBase.NoOp(); + + foreach (string query in new[] + { + "SELECT c.name FROM c OFFSET 0 LIMIT 10", + "SELECT c.name FROM c OFFSET 2147483647 LIMIT 10", + "SELECT c.name FROM c OFFSET 10 LIMIT 0", + "SELECT c.name FROM c OFFSET 10 LIMIT 2147483647", + "SELECT TOP 0 c.name FROM c", + "SELECT TOP 2147483647 c.name FROM c", + }) + { + List expectedValues = new List(); + FeedIterator resultSetIterator = container.GetItemQueryIterator( + query, + requestOptions: new QueryRequestOptions() { MaxConcurrency = 0 }); + + while (resultSetIterator.HasMoreResults) + { + expectedValues.AddRange(await resultSetIterator.ReadNextAsync()); + } + + Assert.AreEqual(0, expectedValues.Count); + } + } + + await this.CreateIngestQueryDeleteAsync( + ConnectionModes.Direct | ConnectionModes.Gateway, + CollectionTypes.MultiPartition, + QueryTestsBase.NoDocuments, + ImplementationAsync); + } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.GroupBy.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.GroupBy.xml index 3059db631a..d3d4fdae81 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.GroupBy.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.GroupBy.xml @@ -10,7 +10,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -24,7 +27,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":24,"end":25},"code":"SC2041","message":"'SELECT *' is not allowed with GROUP BY."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -38,7 +44,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":24,"end":25},"code":"SC2041","message":"'SELECT *' is not allowed with GROUP BY."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -467,7 +476,10 @@ GROUP BY UPPER(c.name), SUBSTRING(c.address.city, 0, 3)]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":32,"end":39},"code":"SC2102","message":"Property reference 's.score' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."},{"severity":"Error","location":{"start":41,"end":49},"code":"SC2102","message":"Property reference 's.repeat' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Negative.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Negative.xml index 24717578a2..93ab261bc9 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Negative.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Negative.xml @@ -9,7 +9,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":7,"end":14},"code":"SC2005","message":"'BADFUNC' is not a recognized built-in function name."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -28,7 +31,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":336,"end":340},"code":"SC1001","message":"Syntax error, incorrect syntax near 'FROM'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -41,7 +47,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":27,"end":59},"code":"SC2050","message":"The STARTSWITH function requires 2 to 3 argument(s)."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -54,7 +63,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","code":2206,"message":"Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -67,7 +79,10 @@ Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":13,"end":24},"code":"SC2101","message":"Cannot perform an aggregate function on an expression containing an aggregate or a subquery."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -121,7 +136,10 @@ FROM r]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -134,7 +152,10 @@ FROM r]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -147,7 +168,10 @@ FROM r]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.NonValueAggregates.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.NonValueAggregates.xml index dfbfbcf15c..b1c0c88c49 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.NonValueAggregates.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.NonValueAggregates.xml @@ -2364,7 +2364,10 @@ WHERE (c.pk = 1)]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -2414,7 +2417,10 @@ FROM c]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -2425,7 +2431,10 @@ FROM c]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + @@ -2480,7 +2489,10 @@ FROM c]]> Hash - TryCatch resulted in an exception. + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"Errors":["Compositions of aggregates and other expressions are not allowed."]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.OffsetLimit.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.OffsetLimit.xml index 84df99f0a5..5d993aebda 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.OffsetLimit.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.OffsetLimit.xml @@ -333,4 +333,528 @@ GROUP BY c.name]]> + + + OFFSET value beyond lower range + SELECT c.name FROM c OFFSET -1 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":28,"end":29},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + OFFSET value at lower range + SELECT c.name FROM c OFFSET 0 LIMIT 10 + + /key + + Hash + + + + + None + + 0 + 10 + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + OFFSET value at upper range (client) + SELECT c.name FROM c OFFSET 2147483647 LIMIT 10 + + /key + + Hash + + + + + None + + 2147483647 + 10 + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + OFFSET value beyond upper range (client) + SELECT c.name FROM c OFFSET 2147483648 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryInfo":{"distinctType":"None","offset":2147483648,"limit":10,"groupByExpressions":[],"groupByAliases":[],"orderBy":[],"orderByExpressions":[],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"SELECT c.name\nFROM c\nOFFSET 0 LIMIT 2147483658","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":0},"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}]} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'QueryInfo.Offset') + + + + + + OFFSET value beyond upper range (Interop) + SELECT c.name FROM c OFFSET 4294967296 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":28,"end":38},"code":"SC2062","message":"The OFFSET count value exceeds the maximum allowed value."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + OFFSET value beyond lower range - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET -1 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":74,"end":75},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + OFFSET value at lower range - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 0 LIMIT 10 + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + + 0 + 120 + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 0 + 10 + True + + + + + + + OFFSET value at upper range (client) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 2147483647 LIMIT 10 + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + + 0 + 18 + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 2147483647 + 10 + True + + + + + + + OFFSET value beyond upper range (client) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 2147483648 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}],"hybridSearchQueryInfo":{"globalStatisticsQuery":"SELECT COUNT(1) AS documentCount, [{\"totalWordCount\": SUM(_FullTextWordCount(c.text)), \"hitCounts\": [COUNTIF(FullTextContains(c.text, \"swim\"))]}] AS fullTextStatistics\nFROM c","componentQueryInfos":[{"distinctType":"None","offset":0,"limit":20,"groupByExpressions":[],"groupByAliases":[],"orderBy":["Descending"],"orderByExpressions":["_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})"],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"SELECT c._rid, [{\"item\": _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})}] AS orderByItems, {\"payload\": {\"name\": c.name}, \"componentScores\": [_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})]} AS payload\nFROM c\nWHERE ({documentdb-formattableorderbyquery-filter})\nORDER BY _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) DESC\nOFFSET 0 LIMIT 20","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":1}],"componentWithoutPayloadQueryInfos":[],"skip":2147483648,"take":10,"requiresGlobalStatistics":true}} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'HybridSearchQueryInfo.Skip') + + + + + + OFFSET value beyond upper range (Interop) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 4294967296 LIMIT 10 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":74,"end":84},"code":"SC2062","message":"The OFFSET count value exceeds the maximum allowed value."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + LIMIT value beyond lower range + SELECT c.name FROM c OFFSET 10 LIMIT -1 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":37,"end":38},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + LIMIT value at lower range + SELECT c.name FROM c OFFSET 10 LIMIT 0 + + /key + + Hash + + + + + None + + 10 + 0 + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + LIMIT value at upper range (client) + SELECT c.name FROM c OFFSET 10 LIMIT 2147483647 + + /key + + Hash + + + + + None + + 10 + 2147483647 + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + LIMIT value beyond upper range (client) + SELECT c.name FROM c OFFSET 10 LIMIT 2147483648 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryInfo":{"distinctType":"None","offset":10,"limit":2147483648,"groupByExpressions":[],"groupByAliases":[],"orderBy":[],"orderByExpressions":[],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"SELECT c.name\nFROM c\nOFFSET 0 LIMIT 2147483658","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":0},"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}]} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'QueryInfo.Limit') + + + + + + LIMIT value beyond upper range (Interop) + SELECT c.name FROM c OFFSET 10 LIMIT 4294967296 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":37,"end":47},"code":"SC2061","message":"The LIMIT count value exceeds the maximum allowed value."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + LIMIT value beyond lower range - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT -1 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":83,"end":84},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + LIMIT value at lower range - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 0 + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + + 0 + 120 + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 10 + 0 + True + + + + + + + LIMIT value at upper range (client) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 2147483647 + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + + 0 + 18 + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 10 + 2147483647 + True + + + + + + + LIMIT value beyond upper range (client) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 2147483648 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}],"hybridSearchQueryInfo":{"globalStatisticsQuery":"SELECT COUNT(1) AS documentCount, [{\"totalWordCount\": SUM(_FullTextWordCount(c.text)), \"hitCounts\": [COUNTIF(FullTextContains(c.text, \"swim\"))]}] AS fullTextStatistics\nFROM c","componentQueryInfos":[{"distinctType":"None","offset":0,"limit":20,"groupByExpressions":[],"groupByAliases":[],"orderBy":["Descending"],"orderByExpressions":["_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})"],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"SELECT c._rid, [{\"item\": _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})}] AS orderByItems, {\"payload\": {\"name\": c.name}, \"componentScores\": [_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})]} AS payload\nFROM c\nWHERE ({documentdb-formattableorderbyquery-filter})\nORDER BY _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) DESC\nOFFSET 0 LIMIT 20","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":1}],"componentWithoutPayloadQueryInfos":[],"skip":10,"take":2147483648,"requiresGlobalStatistics":true}} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'HybridSearchQueryInfo.Take') + + + + + + LIMIT value beyond upper range (Interop) - hybrid search + SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 4294967296 + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":83,"end":93},"code":"SC2061","message":"The LIMIT count value exceeds the maximum allowed value."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Top.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Top.xml index 101e60d336..88fe9e438e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Top.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/QueryPlanBaselineTests.Top.xml @@ -343,4 +343,258 @@ GROUP BY c.name]]> + + + TOP value beyond lower range + SELECT TOP -1 c.name FROM c + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":11,"end":12},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + TOP value at lower range + SELECT TOP 0 c.name FROM c + + /key + + Hash + + + + + None + 0 + + + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + TOP value at upper range (client) + SELECT TOP 2147483647 c.name FROM c + + /key + + Hash + + + + + None + 2147483647 + + + + + + + + + False + + + + [[],"Infinity") + + + + + + + + + TOP value beyond upper range (client) + SELECT TOP 2147483648 c.name FROM c + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryInfo":{"distinctType":"None","top":2147483648,"groupByExpressions":[],"groupByAliases":[],"orderBy":[],"orderByExpressions":[],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":0},"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}]} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'QueryInfo.Top') + + + + + + TOP value beyond upper range (Interop) + SELECT TOP 4294967296 c.name FROM c + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":11,"end":21},"code":"SC2060","message":"The count value provided for a TOP clause must be an integer."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + TOP value beyond lower range - hybrid search + SELECT TOP -1 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":11,"end":12},"code":"SC1001","message":"Syntax error, incorrect syntax near '-'."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + + + + TOP value at lower range - hybrid search + SELECT TOP 0 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + 120 + + + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 0 + True + + + + + + + TOP value at upper range (client) - hybrid search + SELECT TOP 2147483647 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) + + /key + + Hash + + + + + + [[],"Infinity") + + + + SELECT COUNT(1) AS documentCount, [{"totalWordCount": SUM(_FullTextWordCount(c.text)), "hitCounts": [COUNTIF(FullTextContains(c.text, "swim"))]}] AS fullTextStatistics +FROM c + + None + 4294967294 + + + + + Descending + + + _FullTextScore(c.text, ["swim"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) + + + + + False + + + 2147483647 + True + + + + + + + TOP value beyond upper range (client) - hybrid search + SELECT TOP 2147483648 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"queryRanges":[{"min":[],"max":"Infinity","isMinInclusive":true,"isMaxInclusive":false}],"hybridSearchQueryInfo":{"globalStatisticsQuery":"SELECT COUNT(1) AS documentCount, [{\"totalWordCount\": SUM(_FullTextWordCount(c.text)), \"hitCounts\": [COUNTIF(FullTextContains(c.text, \"swim\"))]}] AS fullTextStatistics\nFROM c","componentQueryInfos":[{"distinctType":"None","top":0,"groupByExpressions":[],"groupByAliases":[],"orderBy":["Descending"],"orderByExpressions":["_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})"],"aggregates":[],"hasSelectValue":0,"rewrittenQuery":"SELECT TOP 4294967296 c._rid, [{\"item\": _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})}] AS orderByItems, {\"payload\": {\"name\": c.name}, \"componentScores\": [_FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0})]} AS payload\nFROM c\nWHERE ({documentdb-formattableorderbyquery-filter})\nORDER BY _FullTextScore(c.text, [\"swim\"], {documentdb-formattablehybridsearchquery-totaldocumentcount}, {documentdb-formattablehybridsearchquery-totalwordcount-0}, {documentdb-formattablehybridsearchquery-hitcountsarray-0}) DESC","groupByAliasToAggregateType":{},"hasNonStreamingOrderBy":1}],"componentWithoutPayloadQueryInfos":[],"take":2147483648,"requiresGlobalStatistics":true}} +System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'HybridSearchQueryInfo.Take') + + + + + + TOP value beyond upper range (Interop) - hybrid search + SELECT TOP 4294967296 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) + + /key + + Hash + + + Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException : TryCatch resulted in an exception. +Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":11,"end":21},"code":"SC2060","message":"The count value provided for a TOP clause must be an integer."}]} +System.Runtime.InteropServices.COMException : 0x800A0B00 + + + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/NonStreamingOrderByQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/NonStreamingOrderByQueryTests.cs index 573057951d..8b577b5bdb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/NonStreamingOrderByQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/NonStreamingOrderByQueryTests.cs @@ -363,8 +363,8 @@ private static async Task RunHybridSearchTest(HybridSearchTest testCase) ranges: ranges, requiresGlobalStatistics: testCase.RequiresGlobalStatistics, pageSize: testCase.PageSize, - skip: testCase.Skip, - take: testCase.Take); + skip: (uint?)testCase.Skip, + take: (uint?)testCase.Take); Assert.AreEqual(expectedIndices.Count(), results.Count); @@ -447,8 +447,8 @@ private static async Task RunParityTests( IReadOnlyList ranges, bool requiresGlobalStatistics, int pageSize, - int? skip, - int? take) + uint? skip, + uint? take) { TryCatch tryCreatePipeline = PipelineFactory.MonadicCreate( documentContainer, @@ -1583,7 +1583,7 @@ private static void FischerYatesShuffle(IList list) } } - private static HybridSearchQueryInfo Create2ItemHybridSearchQueryInfo(bool requiresGlobalStatistics, int? skip, int? take) + private static HybridSearchQueryInfo Create2ItemHybridSearchQueryInfo(bool requiresGlobalStatistics, uint? skip, uint? take) { return new HybridSearchQueryInfo { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs index 7ecce80a1e..f6207fd291 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs @@ -3,20 +3,20 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; + using System.Linq; + using System.Text; using System.Xml; - using Microsoft.Azure.Documents; - using Microsoft.Azure.Documents.Routing; using Microsoft.Azure.Cosmos.Query.Core; - using Microsoft.Azure.Cosmos.Test.BaselineTest; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Newtonsoft.Json; - using Microsoft.Azure.Cosmos.Query.Core.QueryPlan; using Microsoft.Azure.Cosmos.Query.Core.Monads; - using System.Linq; using Microsoft.Azure.Cosmos.Query.Core.Pipeline.Aggregate; using Microsoft.Azure.Cosmos.Query.Core.Pipeline.CrossPartition.OrderBy; - using Microsoft.Azure.Cosmos.Serialization.HybridRow.Schemas; - + using Microsoft.Azure.Cosmos.Query.Core.QueryPlan; + using Microsoft.Azure.Cosmos.Test.BaselineTest; + using Microsoft.Azure.Documents; + using Microsoft.Azure.Documents.Routing; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Newtonsoft.Json; + /// /// Tests for . /// @@ -1144,6 +1144,56 @@ public void Top() Hash( @"TOP with GROUP BY", @"SELECT TOP 5 VALUE c.name FROM c GROUP BY c.name", + @"/key"), + + Hash( + @"TOP value beyond lower range", + @"SELECT TOP -1 c.name FROM c", + @"/key"), + + Hash( + @"TOP value at lower range", + @"SELECT TOP 0 c.name FROM c", + @"/key"), + + Hash( + @"TOP value at upper range (client)", + @"SELECT TOP 2147483647 c.name FROM c", + @"/key"), + + Hash( + @"TOP value beyond upper range (client)", + @"SELECT TOP 2147483648 c.name FROM c", + @"/key"), + + Hash( + @"TOP value beyond upper range (Interop)", + @"SELECT TOP 4294967296 c.name FROM c", + @"/key"), + + Hash( + @"TOP value beyond lower range - hybrid search", + @"SELECT TOP -1 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) ", + @"/key"), + + Hash( + @"TOP value at lower range - hybrid search", + @"SELECT TOP 0 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) ", + @"/key"), + + Hash( + @"TOP value at upper range (client) - hybrid search", + @"SELECT TOP 2147483647 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) ", + @"/key"), + + Hash( + @"TOP value beyond upper range (client) - hybrid search", + @"SELECT TOP 2147483648 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) ", + @"/key"), + + Hash( + @"TOP value beyond upper range (Interop) - hybrid search", + @"SELECT TOP 4294967296 c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) ", @"/key") }; @@ -1207,6 +1257,106 @@ public void OffsetLimit() @"OFFSET LIMIT and partition filter but group by", @"SELECT c.name FROM c WHERE c.key = 5 GROUP BY c.name OFFSET 1 LIMIT 2", @"/key"), + + Hash( + @"OFFSET value beyond lower range", + @"SELECT c.name FROM c OFFSET -1 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value at lower range", + @"SELECT c.name FROM c OFFSET 0 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value at upper range (client)", + @"SELECT c.name FROM c OFFSET 2147483647 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value beyond upper range (client)", + @"SELECT c.name FROM c OFFSET 2147483648 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value beyond upper range (Interop)", + @"SELECT c.name FROM c OFFSET 4294967296 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value beyond lower range - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET -1 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value at lower range - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 0 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value at upper range (client) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 2147483647 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value beyond upper range (client) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 2147483648 LIMIT 10", + @"/key"), + + Hash( + @"OFFSET value beyond upper range (Interop) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 4294967296 LIMIT 10", + @"/key"), + + Hash( + @"LIMIT value beyond lower range", + @"SELECT c.name FROM c OFFSET 10 LIMIT -1", + @"/key"), + + Hash( + @"LIMIT value at lower range", + @"SELECT c.name FROM c OFFSET 10 LIMIT 0", + @"/key"), + + Hash( + @"LIMIT value at upper range (client)", + @"SELECT c.name FROM c OFFSET 10 LIMIT 2147483647", + @"/key"), + + Hash( + @"LIMIT value beyond upper range (client)", + @"SELECT c.name FROM c OFFSET 10 LIMIT 2147483648", + @"/key"), + + Hash( + @"LIMIT value beyond upper range (Interop)", + @"SELECT c.name FROM c OFFSET 10 LIMIT 4294967296", + @"/key"), + + Hash( + @"LIMIT value beyond lower range - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT -1", + @"/key"), + + Hash( + @"LIMIT value at lower range - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 0", + @"/key"), + + Hash( + @"LIMIT value at upper range (client) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 2147483647", + @"/key"), + + Hash( + @"LIMIT value beyond upper range (client) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 2147483648", + @"/key"), + + Hash( + @"LIMIT value beyond upper range (Interop) - hybrid search", + @"SELECT c.name FROM c ORDER BY RANK FullTextScore(c.text, ['swim']) OFFSET 10 LIMIT 4294967296", + @"/key"), }; this.ExecuteTestSuite(testVariations); @@ -1686,8 +1836,17 @@ public QueryPlanBaselineTestNegativeOutput(Exception exception) } public override void SerializeAsXml(XmlWriter xmlWriter) - { - xmlWriter.WriteElementString(nameof(this.Exception), this.Exception.Message); + { + StringBuilder stringBuilder = new StringBuilder(); + + Exception ex = this.Exception; + while (ex != null) + { + stringBuilder.AppendLine($"{ex.GetType()} : {ex.Message}"); + ex = ex.InnerException; + } + + xmlWriter.WriteElementString(nameof(this.Exception), stringBuilder.ToString()); } public Exception Exception { get; } @@ -1709,9 +1868,9 @@ public override void SerializeAsXml(XmlWriter xmlWriter) xmlWriter.WriteEndElement(); } - private static void WriteQueryInfoAsXML(QueryInfo queryInfo, XmlWriter writer) + private static void WriteQueryInfoAsXML(QueryInfo queryInfo, XmlWriter writer, string elementName, bool includeRewrittenQuery) { - writer.WriteStartElement(nameof(QueryInfo)); + writer.WriteStartElement(elementName); writer.WriteElementString(nameof(queryInfo.DistinctType), queryInfo.DistinctType.ToString()); writer.WriteElementString(nameof(queryInfo.Top), queryInfo.Top.ToString()); writer.WriteElementString(nameof(queryInfo.Offset), queryInfo.Offset.ToString()); @@ -1756,6 +1915,12 @@ private static void WriteQueryInfoAsXML(QueryInfo queryInfo, XmlWriter writer) } writer.WriteEndElement(); writer.WriteElementString(nameof(queryInfo.HasSelectValue), queryInfo.HasSelectValue.ToString()); + + if (includeRewrittenQuery && queryInfo.RewrittenQuery != null) + { + WriteRewrittenQueryAsXML(queryInfo.RewrittenQuery, writer); + } + writer.WriteEndElement(); } @@ -1791,7 +1956,7 @@ private static void WritePartitionQueryExecutionInfoAsXML(PartitionedQueryExecut { if (info.QueryInfo != null) { - WriteQueryInfoAsXML(info.QueryInfo, writer); + WriteQueryInfoAsXML(info.QueryInfo, writer, elementName: nameof(QueryInfo), includeRewrittenQuery: false); } if (info.QueryRanges != null) @@ -1799,10 +1964,60 @@ private static void WritePartitionQueryExecutionInfoAsXML(PartitionedQueryExecut WriteQueryRangesAsXML(info.QueryRanges, writer); } - if (info.QueryInfo.RewrittenQuery != null) + if (info.QueryInfo?.RewrittenQuery != null) { WriteRewrittenQueryAsXML(info.QueryInfo.RewrittenQuery, writer); + } + + if(info.HybridSearchQueryInfo != null) + { + WriteHybridQueryInfoAsXML(info.HybridSearchQueryInfo, writer); } - } + } + + private static void WriteHybridQueryInfoAsXML(HybridSearchQueryInfo hybridsearchQueryInfo, XmlWriter writer) + { + writer.WriteStartElement(nameof(HybridSearchQueryInfo)); + + if (hybridsearchQueryInfo.GlobalStatisticsQuery != null) + { + writer.WriteElementString(nameof(hybridsearchQueryInfo.GlobalStatisticsQuery), hybridsearchQueryInfo.GlobalStatisticsQuery); + } + + if (hybridsearchQueryInfo.ComponentQueryInfos != null) + { + foreach (QueryInfo componentQueryInfo in hybridsearchQueryInfo.ComponentQueryInfos) + { + WriteQueryInfoAsXML(componentQueryInfo, writer, elementName: "componentQueryInfo", includeRewrittenQuery: true); + } + } + + if (hybridsearchQueryInfo.ComponentWithoutPayloadQueryInfos != null) + { + foreach (QueryInfo componentWithoutPayloadQueryInfo in hybridsearchQueryInfo.ComponentWithoutPayloadQueryInfos) + { + WriteQueryInfoAsXML(componentWithoutPayloadQueryInfo, writer, elementName: "componentWithoutPayloadQueryInfos", includeRewrittenQuery: true); + } + } + + if (hybridsearchQueryInfo.ProjectionQueryInfo != null) + { + WriteQueryInfoAsXML(hybridsearchQueryInfo.ProjectionQueryInfo, writer, elementName: "projectionQueryInfo", includeRewrittenQuery: true); + } + + if (hybridsearchQueryInfo.Skip.HasValue) + { + writer.WriteElementString(nameof(hybridsearchQueryInfo.Skip), hybridsearchQueryInfo.Skip.ToString()); + } + + if (hybridsearchQueryInfo.Take.HasValue) + { + writer.WriteElementString(nameof(hybridsearchQueryInfo.Take), hybridsearchQueryInfo.Take.ToString()); + } + + writer.WriteElementString(nameof(hybridsearchQueryInfo.RequiresGlobalStatistics), hybridsearchQueryInfo.RequiresGlobalStatistics.ToString()); + + writer.WriteEndElement(); + } } }