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
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static CosmosClient()
{
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2018_12_31;
HttpConstants.Versions.CurrentVersionUTF8 = Encoding.UTF8.GetBytes(HttpConstants.Versions.CurrentVersion);

// V3 always assumes assemblies exists
// Shall revisit on feedback
ServiceInteropWrapper.AssembliesExist = new Lazy<bool>(() => true);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<ClientVersion>3.0.0.11-preview</ClientVersion>
<DirectVersion>3.0.0.27-preview</DirectVersion>
<DirectVersion>3.0.0.28-preview</DirectVersion>
<Version Condition=" '$(IsNightly)' == '1' ">$(ClientVersion)-nightly$(CurrentDate)</Version>
<Version Condition=" '$(IsNightly)' == '0' Or '$(IsNightly)' == '' ">$(ClientVersion)</Version>
<FileVersion>$(VersionPrefix)</FileVersion>
Expand Down Expand Up @@ -42,11 +42,11 @@
</ItemGroup>

<ItemGroup Condition=" '$(SignAssembly)' == 'true' ">
<PackageReference Include="Microsoft.Azure.Cosmos.Direct" Version="$(DirectVersion)" />
<PackageReference Include="Microsoft.Azure.Cosmos.Direct" Version="[$(DirectVersion)]" />
</ItemGroup>

<ItemGroup Condition=" '$(SignAssembly)' != 'true' ">
<PackageReference Include="Microsoft.Azure.Cosmos.Direct.MyGet" Version="$(DirectVersion)" />
<PackageReference Include="Microsoft.Azure.Cosmos.Direct.MyGet" Version="[$(DirectVersion)]" />
</ItemGroup>

<ItemGroup>
Expand All @@ -61,5 +61,5 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);DOCDBCLIENT;NETSTANDARD20</DefineConstants>
<DefineConstants Condition=" '$(SignAssembly)' == 'true' ">$(DefineConstants);SignAssembly</DefineConstants>
</PropertyGroup>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Query/CosmosQueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class CosmosQueryContext
public ResourceType ResourceTypeEnum { get; }
public OperationType OperationTypeEnum { get; }
public Type ResourceType { get; }
public SqlQuerySpec SqlQuerySpec { get; }
public SqlQuerySpec SqlQuerySpec { get; internal set; }
public CosmosQueryRequestOptions QueryRequestOptions { get; }
public bool IsContinuationExpected { get; }
public bool AllowNonValueAggregateQuery { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Cosmos.Query
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.ParallelQuery;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Routing;

/// <summary>
/// Factory class for creating the appropriate DocumentQueryExecutionContext for the provided type of query.
Expand Down Expand Up @@ -111,11 +112,6 @@ private async Task<IDocumentQueryExecutionContext> CreateItemQueryExecutionConte
{
collection = await collectionCache.ResolveCollectionAsync(request, cancellationToken);
}

if (this.cosmosQueryContext.QueryRequestOptions != null && this.cosmosQueryContext.QueryRequestOptions.PartitionKey != null && this.cosmosQueryContext.QueryRequestOptions.PartitionKey.Equals(PartitionKey.None))
{
this.cosmosQueryContext.QueryRequestOptions.PartitionKey = PartitionKey.FromInternalKey(collection.GetNoneValue());
}
}

if(collection == null)
Expand Down Expand Up @@ -195,6 +191,14 @@ public static async Task<IDocumentQueryExecutionContext> CreateSpecializedDocume
string collectionRid,
CancellationToken cancellationToken)
{
if (!string.IsNullOrEmpty(partitionedQueryExecutionInfo.QueryInfo.RewrittenQuery))
if (!string.IsNullOrEmpty(partitionedQueryExecutionInfo.QueryInfo?.RewrittenQuery))
{
cosmosQueryContext.SqlQuerySpec = new SqlQuerySpec(
partitionedQueryExecutionInfo.QueryInfo.RewrittenQuery,
cosmosQueryContext.SqlQuerySpec.Parameters);
}

// Figure out the optimal page size.
long initialPageSize = cosmosQueryContext.QueryRequestOptions.MaxItemCount.GetValueOrDefault(ParallelQueryConfig.GetConfig().ClientInternalPageSize);

Expand Down Expand Up @@ -278,10 +282,21 @@ internal static async Task<List<PartitionKeyRange>> GetTargetPartitionKeyRanges(
List<PartitionKeyRange> targetRanges;
if (queryRequestOptions.PartitionKey != null)
{
// Dis-ambiguate the NonePK if used
PartitionKeyInternal partitionKeyInternal = null;
if (Object.ReferenceEquals(queryRequestOptions.PartitionKey, CosmosContainerSettings.NonePartitionKeyValue))
{
partitionKeyInternal = collection.GetNoneValue();
}
else
{
partitionKeyInternal = new PartitionKey(queryRequestOptions.PartitionKey).InternalKey;
}

targetRanges = await queryClient.GetTargetPartitionKeyRangesByEpkString(
resourceLink,
collection.ResourceId,
new PartitionKey(queryRequestOptions.PartitionKey).InternalKey.GetEffectivePartitionKeyString(collection.PartitionKey));
partitionKeyInternal.GetEffectivePartitionKeyString(collection.PartitionKey));
}
else if (TryGetEpkProperty(queryRequestOptions, out string effectivePartitionKeyString))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ internal CosmosResultSetIteratorCore(
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A query response from cosmos service</returns>
public override Task<CosmosQueryResponse> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<CosmosQueryResponse> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

return this.nextResultSetDelegate(this.continuationToken, this.queryOptions, this.state, cancellationToken)
.ContinueWith(task =>
{
CosmosQueryResponse response = task.Result;
this.continuationToken = response.ContinuationToken;
this.HasMoreResults = response.GetHasMoreResults();
return response;
}, cancellationToken);
CosmosQueryResponse response = await this.nextResultSetDelegate(this.continuationToken, this.queryOptions, this.state, cancellationToken);
this.continuationToken = response.ContinuationToken;
this.HasMoreResults = response.GetHasMoreResults();
return response;
}
}

Expand Down Expand Up @@ -141,19 +137,15 @@ internal CosmosDefaultResultSetIterator(
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A query response from cosmos service</returns>
public override Task<CosmosQueryResponse<T>> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<CosmosQueryResponse<T>> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

return this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken)
.ContinueWith(task =>
{
CosmosQueryResponse<T> response = task.Result;
this.HasMoreResults = response.GetHasMoreResults();
this.continuationToken = response.InternalContinuationToken;

return response;
}, cancellationToken);
CosmosQueryResponse<T> response = await this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken);
this.HasMoreResults = response.GetHasMoreResults();
this.continuationToken = response.InternalContinuationToken;
return response;

}

internal static CosmosQueryResponse<T> CreateCosmosQueryResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,20 +740,8 @@ public async Task NegativeQueryTest()
await resultSet.FetchNextSetAsync();
Assert.Fail("Expected query to fail");
}
catch (AggregateException e)
catch (CosmosException exception) when (exception.StatusCode == HttpStatusCode.BadRequest)
{
CosmosException exception = e.InnerException as CosmosException;

if (exception == null)
{
throw e;
}

if (exception.StatusCode != HttpStatusCode.BadRequest)
{
throw e;
}

Assert.IsTrue(exception.Message.Contains("continuation token limit specified is not large enough"));
}

Expand All @@ -766,20 +754,8 @@ public async Task NegativeQueryTest()
await resultSet.FetchNextSetAsync();
Assert.Fail("Expected query to fail");
}
catch (AggregateException e)
catch (CosmosException exception) when (exception.StatusCode == HttpStatusCode.BadRequest)
{
CosmosException exception = e.InnerException as CosmosException;

if (exception == null)
{
throw e;
}

if (exception.StatusCode != HttpStatusCode.BadRequest)
{
throw e;
}

Assert.IsTrue(exception.Message.Contains("Syntax error, incorrect syntax near"));
}
}
Expand Down Expand Up @@ -828,7 +804,6 @@ public async Task ItemRequestOptionAccessConditionTest()

// Read write non partition Container item.
[TestMethod]
[Ignore] //Temporary ignore till we fix emulator issue
public async Task ReadNonPartitionItemAsync()
{
try
Expand Down Expand Up @@ -978,7 +953,18 @@ private async Task<IList<ToDoActivity>> CreateRandomItems(int pkCount, int perPK
return createdList;
}

private async Task CreateNonPartitionContainerItem()
private Task CreateNonPartitionContainerItem()
{
string itemDefinition = JsonConvert.SerializeObject(this.CreateRandomToDoActivity(id: nonPartitionItemId));
return CosmosItemTests.CreateNonPartitionContainerItem(this.database.Id,
CosmosItemTests.nonPartitionContainerId,
itemDefinition);
}

internal static async Task CreateNonPartitionContainerItem(
string dbName,
string containerName,
string itemDefinition = null)
{
string authKey = ConfigurationManager.AppSettings["MasterKey"];
string endpoint = ConfigurationManager.AppSettings["GatewayEndpoint"];
Expand All @@ -987,33 +973,37 @@ private async Task CreateNonPartitionContainerItem()
Uri baseUri = new Uri(endpoint);
string verb = "POST";
string resourceType = "colls";
string resourceId = string.Format("dbs/{0}", this.database.Id);
string resourceLink = string.Format("dbs/{0}/colls", this.database.Id);
string resourceId = string.Format("dbs/{0}", dbName);
string resourceLink = string.Format("dbs/{0}/colls", dbName);
client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2018-09-17");

string authHeader = this.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");
string authHeader = CosmosItemTests.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");

client.DefaultRequestHeaders.Add("authorization", authHeader);
string containerDefinition = "{\n \"id\": \"" + nonPartitionContainerId + "\"\n}";
string containerDefinition = "{\n \"id\": \"" + containerName + "\"\n}";
StringContent containerContent = new StringContent(containerDefinition);
Uri requestUri = new Uri(baseUri, resourceLink);
await client.PostAsync(requestUri.ToString(), containerContent);
HttpResponseMessage response = await client.PostAsync(requestUri.ToString(), containerContent);
Assert.IsTrue(response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.Conflict, response.ToString());

//Creating non partition Container item.
verb = "POST";
resourceType = "docs";
resourceId = string.Format("dbs/{0}/colls/{1}", this.database.Id, nonPartitionContainerId);
resourceLink = string.Format("dbs/{0}/colls/{1}/docs", this.database.Id, nonPartitionContainerId);
authHeader = this.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");
resourceId = string.Format("dbs/{0}/colls/{1}", dbName, containerName);
resourceLink = string.Format("dbs/{0}/colls/{1}/docs", dbName, containerName);
authHeader = CosmosItemTests.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");

client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);

string itemDefinition = JsonConvert.SerializeObject(this.CreateRandomToDoActivity(id: nonPartitionItemId));
StringContent itemContent = new StringContent(itemDefinition);
requestUri = new Uri(baseUri, resourceLink);
await client.PostAsync(requestUri.ToString(), itemContent);
if (!string.IsNullOrEmpty(itemDefinition))
{
StringContent itemContent = new StringContent(itemDefinition);
requestUri = new Uri(baseUri, resourceLink);
response = await client.PostAsync(requestUri.ToString(), itemContent);
Assert.IsTrue(response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.Conflict, response.ToString());
}
}

private async Task CreateUndefinedPartitionItem()
Expand All @@ -1036,7 +1026,7 @@ private async Task CreateUndefinedPartitionItem()
resourceType = "docs";
resourceId = string.Format("dbs/{0}/colls/{1}", this.database.Id, this.Container.Id);
resourceLink = string.Format("dbs/{0}/colls/{1}/docs", this.database.Id, this.Container.Id);
string authHeader = this.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");
string authHeader = CosmosItemTests.GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, authKey, "master", "1.0");

client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);
Expand All @@ -1048,7 +1038,7 @@ private async Task CreateUndefinedPartitionItem()
await client.PostAsync(requestUri.ToString(), itemContent);
}

private string GenerateMasterKeyAuthorizationSignature(string verb, string resourceId, string resourceType, string key, string keyType, string tokenVersion)
private static string GenerateMasterKeyAuthorizationSignature(string verb, string resourceId, string resourceType, string key, string keyType, string tokenVersion)
{
System.Security.Cryptography.HMACSHA256 hmacSha256 = new System.Security.Cryptography.HMACSHA256 { Key = Convert.FromBase64String(key) };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ WHERE c.key = "arrayOnlyKey"]]></Query>
<Query><![CDATA[SELECT VALUE MIN (c.field)
FROM c
WHERE c.key = "oneArrayKey"]]></Query>
<Aggregation />
<Aggregation><![CDATA[[]]]></Aggregation>
</Result>
<Result>
<Query><![CDATA[SELECT VALUE MIN (c.field)
FROM c
WHERE c.key = "oneObjectKey"]]></Query>
<Aggregation />
<Aggregation><![CDATA[{}]]></Aggregation>
</Result>
<Result>
<Query><![CDATA[SELECT VALUE MIN (c.field)
Expand Down Expand Up @@ -291,13 +291,13 @@ WHERE c.key = "arrayOnlyKey"]]></Query>
<Query><![CDATA[SELECT VALUE MAX (c.field)
FROM c
WHERE c.key = "oneArrayKey"]]></Query>
<Aggregation />
<Aggregation><![CDATA[[]]]></Aggregation>
</Result>
<Result>
<Query><![CDATA[SELECT VALUE MAX (c.field)
FROM c
WHERE c.key = "oneObjectKey"]]></Query>
<Aggregation />
<Aggregation><![CDATA[{}]]></Aggregation>
</Result>
<Result>
<Query><![CDATA[SELECT VALUE MAX (c.field)
Expand Down
Loading