Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryExecuteQuery #837

Merged
merged 14 commits into from
Oct 24, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -156,50 +156,70 @@ private async Task<CosmosQueryExecutionContext> CreateItemQueryExecutionContextA
this.CosmosQueryContext.ContainerResourceId = containerQueryProperties.ResourceId;

PartitionedQueryExecutionInfo partitionedQueryExecutionInfo;
if (this.CosmosQueryContext.QueryClient.ByPassQueryParsing())
if (this.inputParameters.PartitionedQueryExecutionInfo != null)
{
// 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
partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanThroughGatewayAsync(
this.CosmosQueryContext.QueryClient,
this.inputParameters.SqlQuerySpec,
this.CosmosQueryContext.ResourceLink,
cancellationToken);
partitionedQueryExecutionInfo = this.inputParameters.PartitionedQueryExecutionInfo;
}
else
{
//todo:elasticcollections this may rely on information from collection cache which is outdated
//if collection is deleted/created with same name.
//need to make it not rely on information from collection cache.
Documents.PartitionKeyDefinition partitionKeyDefinition;
object partitionKeyDefinitionObject;
if (this.inputParameters.Properties != null
&& this.inputParameters.Properties.TryGetValue(InternalPartitionKeyDefinitionProperty, out partitionKeyDefinitionObject))
if (this.CosmosQueryContext.QueryClient.ByPassQueryParsing())
{
if (partitionKeyDefinitionObject is Documents.PartitionKeyDefinition definition)
// 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
partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanThroughGatewayAsync(
this.CosmosQueryContext.QueryClient,
this.inputParameters.SqlQuerySpec,
this.CosmosQueryContext.ResourceLink,
cancellationToken);
}
else
{
//todo:elasticcollections this may rely on information from collection cache which is outdated
//if collection is deleted/created with same name.
//need to make it not rely on information from collection cache.
Documents.PartitionKeyDefinition partitionKeyDefinition;
object partitionKeyDefinitionObject;
if (this.inputParameters.Properties != null
&& this.inputParameters.Properties.TryGetValue(InternalPartitionKeyDefinitionProperty, out partitionKeyDefinitionObject))
{
partitionKeyDefinition = definition;
if (partitionKeyDefinitionObject is Documents.PartitionKeyDefinition definition)
{
partitionKeyDefinition = definition;
}
else
{
throw new ArgumentException(
"partitionkeydefinition has invalid type",
nameof(partitionKeyDefinitionObject));
}
}
else
{
throw new ArgumentException(
"partitionkeydefinition has invalid type",
nameof(partitionKeyDefinitionObject));
partitionKeyDefinition = containerQueryProperties.PartitionKeyDefinition;
}
}
else
{
partitionKeyDefinition = containerQueryProperties.PartitionKeyDefinition;
}

partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanWithServiceInteropAsync(
this.CosmosQueryContext.QueryClient,
this.inputParameters.SqlQuerySpec,
partitionKeyDefinition,
this.inputParameters.PartitionKey != null,
cancellationToken);
partitionedQueryExecutionInfo = await QueryPlanRetriever.GetQueryPlanWithServiceInteropAsync(
this.CosmosQueryContext.QueryClient,
this.inputParameters.SqlQuerySpec,
partitionKeyDefinition,
this.inputParameters.PartitionKey != null,
cancellationToken);
}
}

return await this.CreateFromPartitionedQuerExecutionInfoAsync(
partitionedQueryExecutionInfo,
containerQueryProperties,
cancellationToken);
}

public async Task<CosmosQueryExecutionContext> CreateFromPartitionedQuerExecutionInfoAsync(
PartitionedQueryExecutionInfo partitionedQueryExecutionInfo,
ContainerQueryProperties containerQueryProperties,
CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

List<Documents.PartitionKeyRange> targetRanges = await CosmosQueryExecutionContextFactory.GetTargetPartitionKeyRangesAsync(
this.CosmosQueryContext.QueryClient,
this.CosmosQueryContext.ResourceLink.OriginalString,
Expand Down Expand Up @@ -415,6 +435,7 @@ public struct InputParameters
internal int? MaxBufferedItemCount { get; set; }
internal PartitionKey? PartitionKey { get; set; }
internal IDictionary<string, object> Properties { get; set; }
internal PartitionedQueryExecutionInfo PartitionedQueryExecutionInfo { get; set; }
}
}
}
Loading