Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Incorporate code review feedback
  • Loading branch information
neildsh committed May 14, 2024
commit 8c1e1a6b91f95bc18d982419f8d41586495a91a7
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,19 @@ internal static class QueryPlanRetriever
| QueryFeatures.DCount
| QueryFeatures.NonStreamingOrderBy;

private static readonly QueryFeatures LegacySupportedQueryFeatures =
QueryFeatures.Aggregate
| QueryFeatures.Distinct
| QueryFeatures.GroupBy
| QueryFeatures.MultipleOrderBy
| QueryFeatures.MultipleAggregates
| QueryFeatures.OffsetAndLimit
| QueryFeatures.OrderBy
| QueryFeatures.Top
| QueryFeatures.NonValueAggregate
| QueryFeatures.DCount;
private static readonly QueryFeatures SupportedQueryFeaturesWithoutNonStreamingOrderBy =
SupportedQueryFeatures & (~QueryFeatures.NonStreamingOrderBy);

private static readonly string SupportedQueryFeaturesString = SupportedQueryFeatures.ToString();

private static readonly string LegacySupportedQueryFeaturesString = LegacySupportedQueryFeatures.ToString();
private static readonly string SupportedQueryFeaturesWithoutNonStreamingOrderByString =
SupportedQueryFeaturesWithoutNonStreamingOrderBy.ToString();

private static string GetSupportedQueryFeaturesString(bool isNonStreamingOrderByQueryFeatureDisabled)
{
if (isNonStreamingOrderByQueryFeatureDisabled)
{
return LegacySupportedQueryFeaturesString;
}
else
{
return SupportedQueryFeaturesString;
}
return isNonStreamingOrderByQueryFeatureDisabled ?
SupportedQueryFeaturesWithoutNonStreamingOrderByString :
SupportedQueryFeaturesString;
}

public static async Task<PartitionedQueryExecutionInfo> GetQueryPlanWithServiceInteropAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public class QueryRequestOptions : RequestOptions
/// Direct (optimistic) execution offers improved performance for several kinds of queries such as a single partition streaming query.
/// </value>
public bool EnableOptimisticDirectExecution { get; set; } = ConfigurationManager.IsOptimisticDirectExecutionEnabled(defaultValue: false);

internal bool IsNonStreamingOrderByQueryFeatureDisabled { get; set; } = ConfigurationManager.IsNonStreamingOrderByQueryFeatureDisabled(defaultValue: false);

/// <summary>
/// Gets or sets the maximum number of items that can be buffered client side during
Expand Down Expand Up @@ -191,7 +189,9 @@ public ConsistencyLevel? ConsistencyLevel

internal TestInjections TestSettings { get; set; }

internal FeedRange FeedRange { get; set; }
internal FeedRange FeedRange { get; set; }

internal bool IsNonStreamingOrderByQueryFeatureDisabled { get; set; } = ConfigurationManager.IsNonStreamingOrderByQueryFeatureDisabled(defaultValue: false);

/// <summary>
/// Fill the CosmosRequestMessage headers with the set properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Microsoft.Azure.Cosmos.EmulatorTests.Query
namespace Microsoft.Azure.Cosmos.EmulatorTests.Query
{
using System;
using System.Collections.Generic;
Expand All @@ -15,9 +15,9 @@ namespace Microsoft.Azure.Cosmos.EmulatorTests.Query
using Microsoft.Azure.Cosmos.Query.Core.QueryClient;
using Microsoft.Azure.Cosmos.Query;

[TestClass]
[TestCategory("Query")]
public sealed class NonStreamingOrderByQueryTests : QueryTestsBase
[TestClass]
[TestCategory("Query")]
public sealed class NonStreamingOrderByQueryTests : QueryTestsBase
{
private const string Embedding = "[-0.008861,0.097097,0.100236,0.070044,-0.079279,0.000923,-0.012829,0.064301,-0.029405,-0.009858,-0.017753,0.063115,0.033623,0.019805,0.052704,-0.100458,0.089387,-0.040792,-0.088936,0.110212,-0.044749,0.077675,-0.017062,-0.063745,-0.009502,-0.079371,0.066952,-0.070209,0.063761,-0.038194,-0.046252,0.049983,-0.094985,-0.086341,0.024665,-0.112857,-0.038358,-0.007008,-0.010063,-0.000183,0.068841,0.024942,-0.042561,-0.044576,0.010776,0.006323,0.088285,-0.062522,0.028216,0.088291,0.033231,-0.033732,-0.002995,0.118994,0.000453,0.158588,-0.044475,-0.137629,0.066080,0.062824,-0.128369,-0.087959,0.028080,0.070063,0.046700,-0.083278,-0.118428,0.071118,0.100757,0.017944,0.026296,0.017282,-0.082127,-0.006148,0.002967,-0.032857,-0.076493,-0.072842,-0.055179,-0.081703,0.011437,-0.038698,-0.062540,-0.027899,0.087635,0.031870,0.029164,0.000524,-0.039895,-0.055559,0.024582,-0.030595,0.003942,-0.034500,0.003012,-0.023863,0.033831,0.061476,-0.090183,-0.039206,-0.026586,-0.042763,0.049835,-0.052496,-0.020044,0.073703,0.096775,0.033063,0.000313,-0.022581,-0.141154,0.032095,0.077733,-0.063739,-0.055647,-0.017604,0.044639,-0.062925,-0.001960,0.024665,-0.009416,-0.021381,0.082724,-0.031026,0.027255,0.066198,0.000845,0.008393,0.039434,0.054104,-0.060255,0.034266,0.079435,0.043624,-0.015871,-0.038030,-0.030374,-0.020542,0.007132,0.008708,0.087840,0.017351,-0.089493,0.030182,0.026961,-0.071212,-0.004854,0.007389,0.067203,-0.026351,-0.011460,-0.058723,0.013153,-0.020313,-0.051170,0.002242,0.088222,-0.004267,-0.073523,-0.021874,-0.033585,-0.048553,-0.019119,-0.025310,0.053096,0.111063,0.035042,-0.082811,-0.073749,-0.010048,0.012265,-0.023893,-0.125340,0.026611,0.043258,-0.010473,-0.044428,-0.039251,-0.046891,-0.013008,0.062219,0.078732,-0.086303,0.016901,0.010331,-0.043754,-0.057733,-0.037964,0.024907,0.068143,-0.019992,-0.035030,0.038854,0.034345,-0.048839,-0.105419,0.043013,-0.023374,-0.077629,-0.076465,0.078564,-0.024519,0.041293,-0.032088,-0.007053,0.022618,-0.004657,-0.093970,-0.000199,0.004813,-0.044789,-0.127900,-0.033516,-0.043816,0.033056,-0.057619,0.004901,0.018863,0.039752,0.000739,-0.136350,-0.067819,-0.014856,0.058351,-0.014275,-0.000873,-0.039388,-0.017191,-0.051184,-0.046863,0.006143,-0.075998,-0.064695,0.046676,-0.020558,0.082474,0.160449,-0.027475,0.009541,-0.021876,0.027416,0.078049,0.089309,0.032928,-0.033272,0.048905,0.061164,0.054811,0.024527,-0.034978,-0.018083,-0.077601,0.034112,-0.021121,0.098856,0.019585,-0.058928,-0.016126,-0.011748,0.031588,0.003205,-0.077483,-0.002372,-0.113548,0.047445,-0.027094,-0.032843,0.042378,-0.074703,0.057001,0.012020,0.131156,0.002080,-0.065770,0.112443,0.047786,0.024492,-0.108401,0.016836,0.001478,0.041542,-0.067801,0.102876,-0.052808,-0.136035,0.073852,0.079966,-0.000586,0.034055,-0.053040,0.050461,-0.021550,0.014827,0.077605,-0.024783,-0.082388,0.074410,-0.033689,-0.010982,0.043733]";

Expand Down Expand Up @@ -151,9 +151,9 @@ static async Task ImplementationAsync(Container container, IReadOnlyList<CosmosO
EnableOptimisticDirectExecution = false,
};

if (testCase.RequestOption.HasValue)
{
requestOptions.IsNonStreamingOrderByQueryFeatureDisabled = testCase.RequestOption.Value;
if (testCase.RequestOption.HasValue)
{
requestOptions.IsNonStreamingOrderByQueryFeatureDisabled = testCase.RequestOption.Value;
}

validator.ExpectNonStreamingOrderBy = testCase.ExpectNonStreamingOrderBy;
Expand All @@ -177,7 +177,17 @@ static async Task ImplementationAsync(Container container, IReadOnlyList<CosmosO

Assert.IsTrue(iterator.HasMoreResults);
ResponseMessage responseMessage = await iterator.ReadNextAsync();
Assert.AreEqual(System.Net.HttpStatusCode.OK, responseMessage.StatusCode);

if (responseMessage.StatusCode != System.Net.HttpStatusCode.OK)
{
Trace.WriteLine("Failed test case:");
Trace.WriteLine($"EnvironmentVariable: {testCase.EnvironmentVariable}, RequestOption: {testCase.RequestOption}, ExpectNonStreamingOrderBy: {testCase.ExpectNonStreamingOrderBy}");
Trace.WriteLine($"Unexpected response: {responseMessage.StatusCode}");
Trace.WriteLine(responseMessage.Content.ReadAsString());
Trace.Flush();
Assert.Fail();
}

Assert.AreEqual(validationCount, validator.InvocationCount);
}
}
Expand Down Expand Up @@ -212,10 +222,10 @@ public QueryFeaturesTest(bool? environmentVariable, bool? requestOption, bool ex

private static async Task RunVectorDistanceTestsAsync(Container container, IReadOnlyList<CosmosObject> _)
{
foreach (TestCase testCase in VectorDistanceTestCases)
foreach (TestCase testCase in VectorDistanceTestCases)
{
Trace.WriteLine("Executing test case: ");
Trace.WriteLine(testCase.Query);
Trace.WriteLine(testCase.Query);
FeedIterator<Document> iterator = container.GetItemQueryIterator<Document>(testCase.Query);

List<Document> documents = new List<Document>();
Expand All @@ -236,7 +246,7 @@ private static async Task RunVectorDistanceTestsAsync(Container container, IRead
}

Assert.Fail();
}
}
}
}

Expand Down Expand Up @@ -369,6 +379,20 @@ public void Validate(string supportedQueryFeatures)

private sealed class MockCosmosQueryClient : CosmosQueryClientCore
{
private static readonly QueryFeatures SupportedQueryFeaturesWithoutNonStreamingOrderBy =
QueryFeatures.Aggregate
| QueryFeatures.Distinct
| QueryFeatures.GroupBy
| QueryFeatures.MultipleOrderBy
| QueryFeatures.MultipleAggregates
| QueryFeatures.OffsetAndLimit
| QueryFeatures.OrderBy
| QueryFeatures.Top
| QueryFeatures.NonValueAggregate
| QueryFeatures.DCount;

private static readonly string SupportedQueryFeaturesString = SupportedQueryFeaturesWithoutNonStreamingOrderBy.ToString();

private readonly bool bypassQueryParsing;

private readonly SupportedQueryFeaturesValidator validator;
Expand Down Expand Up @@ -401,6 +425,13 @@ public override Task<PartitionedQueryExecutionInfo> ExecuteQueryPlanRequestAsync
CancellationToken cancellationToken)
{
this.validator.Validate(supportedQueryFeatures);

if (this.validator.ExpectNonStreamingOrderBy)
{
// older emulator in the github repo does not support non-streaming order by, and will send back 400
supportedQueryFeatures = SupportedQueryFeaturesString;
}

return base.ExecuteQueryPlanRequestAsync(
resourceUri,
resourceType,
Expand Down