-
Notifications
You must be signed in to change notification settings - Fork 641
Support hierarchical partition keys for Azure Cosmos #9513
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
Conversation
src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBContainerResource.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kumima can update the cosmos playground example to use this feature?
// Use the resource name as the container name if it's not provided | ||
containerName ??= name; | ||
|
||
var container = new AzureCosmosDBContainerResource(name, containerName, partitionKeyPathsArray[0], builder.Resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebastienros @eerhardt thoughts here? This is the only sketchy part of this change. If there are many this property will only show the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also obsolete this ctor and expose one with the keys. Then add a unit test to have coverage on both even if one is deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we follow this, if hierarchical, single getter will throw. Or we can introduce a private/public ContainerProperties
from AzureCosmosSdk to host the both type keys, so that we don't need to duplicated checking from AzureCosmosSdk.
https://github.com/Azure/azure-cosmos-dotnet-v3/blob/5e6232d25f84074d5008e97670d3e0dc07891f0e/Microsoft.Azure.Cosmos/src/Resource/Settings/ContainerProperties.cs#L408-L419
With public API of ContainerProperties
seems bring more flexibility. Currently we can only custom the partition keys, not all those properties. And if this, we may also need to map all those properties for AzureProvisioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer @sebastienros's suggestion, it's simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidfowl, please check the latest commits, I'm not sure whether those argument checking can be simplified. Are they a bit of duplicated?
And for:
[Obsolete("Use the overload that supports the hierarchical partition keys instead.")]
public AzureCosmosDBContainerResource(string name, string containerName, string partitionKeyPath, AzureCosmosDBDatabaseResource parent)
: this(name, containerName, [partitionKeyPath], parent) { }
The argument exception comes from the other ctor. So given partitionKeyPath
is null, we got partitionKeyPaths
argument exception. Are we going to duplicated ctor logic here again?
// Use the resource name as the container name if it's not provided | ||
containerName ??= name; | ||
|
||
var container = new AzureCosmosDBContainerResource(name, containerName, partitionKeyPathsArray[0], builder.Resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also obsolete this ctor and expose one with the keys. Then add a unit test to have coverage on both even if one is deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Can you take a look at the failed Linux test? |
Thanks @Kumima ! |
Description
Support hierarchical partition keys for Azure Cosmos and make both
AzureInfrastructure
and emulator respect the hierarchical partition keys.As @davidfowl suggested, this won't introduce any break changes.
Awhen initializes a new instance of thenullable
property which isPartitionKeyPaths
has been introduced, andAzureCosmosDBContainerResource
, the first key will be used as the required parameter.Similar with the Azure Cosmos SDK, only the
PartitionKeyPaths
will provide the partition key info.The way to determine whether to use hierarchical partition keys to create the container is to check whetherPartitionKeyPaths
isnull
.If there are further tests need to be added, let me know😊. Another thing I'm not sure is whether we should check the partition keys count, it should be <= 3.
Fixes #9462
Checklist
<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template