Skip to content

Commit

Permalink
Subpartitioning: Adds APIs for public release and increase REST API v…
Browse files Browse the repository at this point in the history
…ersion (#3763)

* initial commit, Http version issues still needs to be resolved

* updateContracts + update Http Version

* updateded version in test

* update contracts

* requested changed

* changed name in comments to subpartitioning from multihash

* undid changes to TestLiteralSerialization.xml

* removed changes to non API.json files

* removed non XXXAPI.json file changes

* changed verbage on public comments

* changed error message to reflect verbage change
  • Loading branch information
NaluTripician authored Mar 21, 2023
1 parent d41f099 commit 1acfaa2
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 151 deletions.
5 changes: 1 addition & 4 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ public class CosmosClient : IDisposable

static CosmosClient()
{
#if PREVIEW
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2020_07_15;
#else
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2018_12_31;
#endif

HttpConstants.Versions.CurrentVersionUTF8 = Encoding.UTF8.GetBytes(HttpConstants.Versions.CurrentVersion);

ServiceInteropWrapper.AssembliesExist = new Lazy<bool>(() =>
Expand Down
7 changes: 1 addition & 6 deletions Microsoft.Azure.Cosmos/src/PartitionKeyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Represents a partition key value list in the Azure Cosmos DB service.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
sealed class PartitionKeyBuilder
public sealed class PartitionKeyBuilder
{
private readonly List<object> partitionKeyValues;

Expand Down
8 changes: 2 additions & 6 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -15,10 +16,6 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Documents;

#if PREVIEW
using System.Collections.Generic;
#endif

/// <summary>
/// Operations for reading or deleting an existing database.
///
Expand Down Expand Up @@ -219,7 +216,6 @@ public async Task<ContainerResponse> CreateContainerIfNotExistsAsync(
nameof(containerProperties.PartitionKey));
}
}
#if PREVIEW
else
{
IReadOnlyList<string> retrivedPartitionKeyPaths = retrivedContainerResponse.Resource.PartitionKeyPaths;
Expand All @@ -236,7 +232,7 @@ public async Task<ContainerResponse> CreateContainerIfNotExistsAsync(
nameof(containerProperties.PartitionKey));
}
}
#endif

return retrivedContainerResponse;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,8 @@ public ContainerProperties(string id, string partitionKeyPath)
/// Initializes a new instance of the <see cref="ContainerProperties"/> class for the Azure Cosmos DB service.
/// </summary>
/// <param name="id">The Id of the resource in the Azure Cosmos service.</param>
/// <param name="partitionKeyPaths">The path to the partition key. Example: /location</param>
#if PREVIEW
public
#else
internal
#endif

ContainerProperties(string id, IReadOnlyList<string> partitionKeyPaths)
/// <param name="partitionKeyPaths">The paths of the hierarchical partition keys. Example: ["/tenantId", "/userId"]</param>
public ContainerProperties(string id, IReadOnlyList<string> partitionKeyPaths)
{
this.Id = id;

Expand Down Expand Up @@ -347,12 +341,11 @@ public string PartitionKeyPath
{
get
{
#if PREVIEW
if (this.PartitionKey?.Kind == PartitionKind.MultiHash && this.PartitionKey?.Paths.Count > 1)
{
throw new NotImplementedException($"This MultiHash collection has more than 1 partition key path please use `PartitionKeyPaths`");
throw new NotImplementedException($"This subpartitioned container has more than 1 partition key path please use `PartitionKeyPaths`");
}
#endif

return this.PartitionKey?.Paths != null && this.PartitionKey.Paths.Count > 0 ? this.PartitionKey?.Paths[0] : null;
}
set
Expand All @@ -377,15 +370,10 @@ public string PartitionKeyPath
}

/// <summary>
/// JSON path used for containers partitioning
/// List of JSON paths used for containers with hierarchical partition keys
/// </summary>
[JsonIgnore]
#if PREVIEW
public
#else
internal
#endif
IReadOnlyList<string> PartitionKeyPaths
public IReadOnlyList<string> PartitionKeyPaths
{
get => this.PartitionKey?.Paths;
set
Expand Down Expand Up @@ -657,12 +645,10 @@ internal IReadOnlyList<IReadOnlyList<string>> PartitionKeyPathTokens
throw new ArgumentOutOfRangeException($"Container {this.Id} is not partitioned");
}

#if PREVIEW
if (this.PartitionKey.Kind == Documents.PartitionKind.MultiHash && this.PartitionKeyPaths == null)
{
throw new ArgumentOutOfRangeException($"Container {this.Id} is not partitioned");
}
#endif

List<IReadOnlyList<string>> partitionKeyPathTokensList = new List<IReadOnlyList<string>>();
foreach (string path in this.PartitionKey?.Paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using HttpConstants = Microsoft.Azure.Documents.HttpConstants;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -22,6 +23,7 @@ public class CosmosContainerTests
{
private CosmosClient cosmosClient = null;
private Cosmos.Database cosmosDatabase = null;

private static long ToEpoch(DateTime dateTime)
{
return (long)(dateTime - new DateTime(1970, 1, 1)).TotalSeconds;
Expand Down Expand Up @@ -713,7 +715,6 @@ public async Task GetFeedRangeOnContainerRecreateScenariosTestAsync()
}
}

#if PREVIEW
//MultiHash container checks.
[TestMethod]
public async Task CreateContainerIfNotExistsAsyncForMultiHashCollectionsTest()
Expand Down Expand Up @@ -798,7 +799,6 @@ public async Task CreateContainerIfNotExistsAsyncForMultiHashCollectionsTest()

}

#endif
[TestMethod]
public async Task StreamPartitionedCreateWithPathDelete()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ public class CosmosMultiHashTest
private Container container = null;
private ContainerProperties containerProperties = null;

private readonly string currentVersion = HttpConstants.Versions.CurrentVersion;


[TestInitialize]
public async Task TestInitialize()
{
HttpConstants.Versions.CurrentVersion = "2020-07-15";
this.client = TestCommon.CreateCosmosClient(true);
this.database = await this.client.CreateDatabaseIfNotExistsAsync("mydb");

Expand All @@ -37,9 +33,6 @@ public async Task Cleanup()
{
await this.database.DeleteAsync();
this.client.Dispose();

HttpConstants.Versions.CurrentVersion = this.currentVersion;
this.client.Dispose();
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,44 +510,7 @@ await container.CreateItemAsync(

await database.DeleteAsync();
client.Dispose();
}

#if PREVIEW
[TestMethod]
public async Task ReadManyMultiplePK()
{
IReadOnlyList<string> pkPaths = new List<string> { "/pk", "/description" };
ContainerProperties containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPaths: pkPaths);
Container container = await this.database.CreateContainerAsync(containerSettings);

for (int i = 0; i < 5; i++)
{
ToDoActivity item = ToDoActivity.CreateRandomToDoActivity();
item.pk = "pk" + i.ToString();
item.id = i.ToString();
item.description = "description" + i;
ItemResponse<ToDoActivity> itemResponse = await container.CreateItemAsync(item);
Assert.AreEqual(HttpStatusCode.Created, itemResponse.StatusCode);
}

List<(string, PartitionKey)> itemList = new List<(string, PartitionKey)>();
for (int i = 0; i < 5; i++)
{
PartitionKey partitionKey = new PartitionKeyBuilder()
.Add("pk" + i)
.Add("description" + i)
.Build();

itemList.Add((i.ToString(), partitionKey));
}

FeedResponse<ToDoActivity> feedResponse = await container.ReadManyItemsAsync<ToDoActivity>(itemList);
Assert.IsNotNull(feedResponse);
Assert.AreEqual(feedResponse.Count, 5);
Assert.IsTrue(feedResponse.Headers.RequestCharge > 0);
Assert.IsNotNull(feedResponse.Diagnostics);
}
#endif
}

private class NestedToDoActivity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ public void ApiVersionTest()
}
catch(ArgumentNullException)
{ }
#if PREVIEW

Assert.AreEqual(HttpConstants.Versions.v2020_07_15, HttpConstants.Versions.CurrentVersion);
CollectionAssert.AreEqual(Encoding.UTF8.GetBytes(HttpConstants.Versions.v2020_07_15), HttpConstants.Versions.CurrentVersionUTF8);
#else
Assert.AreEqual(HttpConstants.Versions.v2018_12_31, HttpConstants.Versions.CurrentVersion);
CollectionAssert.AreEqual(Encoding.UTF8.GetBytes(HttpConstants.Versions.v2018_12_31), HttpConstants.Versions.CurrentVersionUTF8);
#endif

ulong capabilitites = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities();
Assert.AreEqual(capabilitites & (ulong)SDKSupportedCapabilities.PartitionMerge, (ulong)SDKSupportedCapabilities.PartitionMerge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,32 +284,10 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedPolicy get_ChangeFeedPolicy();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.Generic.IReadOnlyList`1[System.String] get_PartitionKeyPaths()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.Collections.Generic.IReadOnlyList`1[System.String] get_PartitionKeyPaths();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.Generic.IReadOnlyList`1[System.String] PartitionKeyPaths[Newtonsoft.Json.JsonIgnoreAttribute()]": {
"Type": "Property",
"Attributes": [
"JsonIgnoreAttribute"
],
"MethodInfo": "System.Collections.Generic.IReadOnlyList`1[System.String] PartitionKeyPaths;CanRead:True;CanWrite:True;System.Collections.Generic.IReadOnlyList`1[System.String] get_PartitionKeyPaths();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PartitionKeyPaths(System.Collections.Generic.IReadOnlyList`1[System.String]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void .ctor(System.String, System.Collections.Generic.IReadOnlyList`1[System.String])": {
"Type": "Constructor",
"Attributes": [],
"MethodInfo": "[Void .ctor(System.String, System.Collections.Generic.IReadOnlyList`1[System.String]), Void .ctor(System.String, System.Collections.Generic.IReadOnlyList`1[System.String])]"
},
"Void set_ChangeFeedPolicy(Microsoft.Azure.Cosmos.ChangeFeedPolicy)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Void set_ChangeFeedPolicy(Microsoft.Azure.Cosmos.ChangeFeedPolicy);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_PartitionKeyPaths(System.Collections.Generic.IReadOnlyList`1[System.String])": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Void set_PartitionKeyPaths(System.Collections.Generic.IReadOnlyList`1[System.String]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
}
},
"NestedTypes": {}
Expand Down Expand Up @@ -384,47 +362,6 @@
}
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
"Microsoft.Azure.Cosmos.PartitionKey Build()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKey Build();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(Boolean)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(Double)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(Double);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(System.String)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKeyBuilder Add(System.String);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder AddNoneType()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKeyBuilder AddNoneType();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.PartitionKeyBuilder AddNullValue()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PartitionKeyBuilder AddNullValue();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void .ctor()": {
"Type": "Constructor",
"Attributes": [],
"MethodInfo": "[Void .ctor(), Void .ctor()]"
}
},
"NestedTypes": {}
}
},
"Members": {},
Expand Down
Loading

0 comments on commit 1acfaa2

Please sign in to comment.