Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.QueryPlan
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.QueryClient;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing;
using OperationType = Documents.OperationType;
using PartitionKeyDefinition = Documents.PartitionKeyDefinition;
using ResourceType = Documents.ResourceType;
Expand Down Expand Up @@ -48,6 +48,11 @@ private static string GetSupportedQueryFeaturesString(bool isHybridSearchQueryPl
return isHybridSearchQueryPlanOptimizationDisabled ?
SupportedQueryFeaturesWithHybridSearchQueryPlanOptimizationDisabledString :
SupportedQueryFeaturesString;
}

public static bool BypassQueryParsing()
{
return Documents.CustomTypeExtensions.ByPassQueryParsing() || ConfigurationManager.ForceBypassQueryParsing();
}

public static async Task<PartitionedQueryExecutionInfo> GetQueryPlanWithServiceInteropAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private async Task<Tuple<DocumentFeedResponse<CosmosElement>, string>> ExecuteOn
else
{
// The query is going to become a full fan out, but we go one partition at a time.
if (ServiceInteropAvailable())
if (!QueryPlanRetriever.BypassQueryParsing())
{
// Get the routing map provider
CollectionCache collectionCache = await this.Client.GetCollectionCacheAsync();
Expand Down Expand Up @@ -248,11 +248,6 @@ private static bool PhysicalPartitionKeyRangeIdProvided(DefaultDocumentQueryExec
return !string.IsNullOrEmpty(context.PartitionKeyRangeId);
}

private static bool ServiceInteropAvailable()
{
return !CustomTypeExtensions.ByPassQueryParsing();
}

private async Task<Tuple<PartitionRoutingHelper.ResolvedRangeInfo, IReadOnlyList<Range<string>>>> TryGetTargetPartitionKeyRangeAsync(
DocumentServiceRequest request,
ContainerProperties collection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static async Task<IDocumentQueryExecutionContext> CreateDocumentQueryExec

// For non-Windows platforms(like Linux and OSX) in .NET Core SDK, we cannot use ServiceInterop, so need to bypass in that case.
// We are also now bypassing this for 32 bit host process running even on Windows as there are many 32 bit apps that will not work without this
if (CustomTypeExtensions.ByPassQueryParsing())
if (QueryPlanRetriever.BypassQueryParsing())
{
// We create a ProxyDocumentQueryExecutionContext that will be initialized with DefaultDocumentQueryExecutionContext
// which will be used to send the query to Gateway and on getting 400(bad request) with 1004(cross partition query not servable), we initialize it with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public override async Task<List<PartitionKeyRange>> GetTargetPartitionKeyRangesA

public override bool BypassQueryParsing()
{
return CustomTypeExtensions.ByPassQueryParsing();
return QueryPlanRetriever.BypassQueryParsing();
}

public override void ClearSessionTokenCache(string collectionFullName)
Expand Down
21 changes: 20 additions & 1 deletion Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ internal static class ConfigurationManager
/// be removed once binary encoding is enabled by default for both preview
/// and GA.
/// </summary>
internal static readonly string TcpChannelMultiplexingEnabled = "AZURE_COSMOS_TCP_CHANNEL_MULTIPLEX_ENABLED";
internal static readonly string TcpChannelMultiplexingEnabled = "AZURE_COSMOS_TCP_CHANNEL_MULTIPLEX_ENABLED";

/// <summary>
/// A read-only string containing the environment variable name for bypassing query parsing.
/// and GA.
/// </summary>
internal static readonly string BypassQueryParsing = "AZURE_COSMOS_BYPASS_QUERY_PARSING";

public static T GetEnvironmentVariable<T>(string variable, T defaultValue)
{
Expand Down Expand Up @@ -357,5 +363,18 @@ public static bool IsTcpChannelMultiplexingEnabled()
variable: ConfigurationManager.TcpChannelMultiplexingEnabled,
defaultValue: false);
}

/// <summary>
/// Gets the boolean value indicating if channel multiplexing enabled on TCP channel.
/// Default: false
/// </summary>
/// <returns>A boolean flag indicating if channel multiplexing is enabled.</returns>
public static bool ForceBypassQueryParsing()
{
return ConfigurationManager
.GetEnvironmentVariable(
variable: ConfigurationManager.BypassQueryParsing,
defaultValue: false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.Azure.Cosmos.EmulatorTests.Query
using Microsoft.Azure.Cosmos.Core.Utf8;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.CosmosElements.Numbers;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.QueryPlan;
using Microsoft.Azure.Cosmos.SDK.EmulatorTests.QueryOracle;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Documents;
Expand Down Expand Up @@ -645,7 +646,7 @@ private async Task TestMalformedPipelinedContinuationTokenRunner(
public void ServiceInteropUsedByDefault()
{
// Test initialie does load CosmosClient
Assert.IsFalse(CustomTypeExtensions.ByPassQueryParsing());
Assert.IsFalse(QueryPlanRetriever.BypassQueryParsing());
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public void ByPassQueryParsing()
{
if (IntPtr.Size == 8)
{
Assert.IsFalse(Documents.CustomTypeExtensions.ByPassQueryParsing());
Assert.IsFalse(Query.Core.QueryPlan.QueryPlanRetriever.BypassQueryParsing());
}
else
{
Assert.IsTrue(Documents.CustomTypeExtensions.ByPassQueryParsing());
Assert.IsTrue(Query.Core.QueryPlan.QueryPlanRetriever.BypassQueryParsing());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,74 @@ public async Task ServiceInterop_E_UNEXPECTED()
Assert.IsNotNull(cosmosException.Diagnostics);
}

[TestMethod]
public void TestBypassQueryParsing()
{
Assert.IsFalse(QueryPlanRetriever.BypassQueryParsing());

foreach ((string name, string value, bool expectedValue) in new[]
{
// Environment variables are case insensitive in windows
("AZURE_COSMOS_BYPASS_QUERY_PARSING", "true", true),
("AZURE_COSMOS_bypass_query_parsing", "True", true),
("azure_cosmos_bypass_query_parsing", "TRUE", true),
("Azure_Cosmos_Bypass_Query_Parsing", "truE", true),

("AZURE_COSMOS_BYPASS_QUERY_PARSING", "false", false),
("AZURE_COSMOS_bypass_query_parsing", "False", false),
("azure_cosmos_bypass_query_parsing", "FALSE", false),
("Azure_Cosmos_Bypass_Query_Parsing", "falsE", false),

("AZURE_COSMOS_BYPASS_QUERY_PARSING", string.Empty, false)
})
{
try
{
// Test new value
Environment.SetEnvironmentVariable(name, value);
Assert.AreEqual(
expectedValue,
QueryPlanRetriever.BypassQueryParsing(),
$"EnvironmentVariable:'{name}', value:'{value}', expected:'{expectedValue}', actual:'{QueryPlanRetriever.BypassQueryParsing()}'");
}
finally
{
// Remove side effects.
Environment.SetEnvironmentVariable(name, null);
}
}

foreach (string value in new[]
{
"'",
"-",
"asdf",
"'true'",
"'false'"
})
{
bool receivedException = false;
try
{
// Test new value
Environment.SetEnvironmentVariable("AZURE_COSMOS_BYPASS_QUERY_PARSING", value);
bool _ = QueryPlanRetriever.BypassQueryParsing();
}
catch (FormatException fe)
{
Assert.IsTrue(fe.ToString().Contains($@"String '{value}' was not recognized as a valid Boolean."));
receivedException = true;
}
finally
{
// Remove side effects.
Environment.SetEnvironmentVariable("AZURE_COSMOS_BYPASS_QUERY_PARSING", null);
}

Assert.IsTrue(receivedException, $"Expected exception was not received for value '{value}'");
}
}

[TestMethod]
public async Task SanityTests()
{
Expand Down
Loading