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

[Internal] Subpartitioning: Adds SDK changes to support subpartitioning. #1658

Merged
merged 49 commits into from
Jul 31, 2020

Conversation

SrinikhilReddy
Copy link
Contributor

@SrinikhilReddy SrinikhilReddy commented Jun 24, 2020

SDK Changes to support Subpartitioning.

  1. Adds the new PartitionKind 'MultiHash' which accepts multiple Partition keys.
  2. Operations currently supported
    1. Document CRUD operations with MultiHash Partition Kind.
  3. Changes done:
    1. New Class PartitionKeyBuilder.
    2. New ContainerProperties constructor that accepts an IReadOnlyList<string> object as multiple partition key paths
    3. Changes to extract multiple partition keys from the Resource object.

Sample usage of Collection create with MultiHash Partition kind and multiple partition key paths.

CosmosClient client = TestCommon.CreateCosmosClient(true);
Cosmos.Database database = await client.CreateDatabaseAsync("mydb");

ContainerProperties containerProperties = new ContainerProperties("mycoll", new List<string>{"/Zipcode","/City"});
Container container = await database.CreateContainerAsync(containerProperties);

Sample Document Create, where the PartitionKey is extracted from the resource stream.

Document  doc1 = new Document { Id = "Id1" };
doc1.SetValue("ZipCode", 15232);
doc1.SetValue("Address", "Pittsburgh");
await container.CreateItemAsync<Document>(doc1);

Reading back the document with the PartitionKey set during the read call.

PartitionKey partitionKey = new PartitionKeyBuilder()
                .Add(15232)
                .Add("Pittsburgh")
                .Build();                    
Document readDocument = (await container.ReadItemAsync<Document>("Id1", partitionKey )).Resource;

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

@SrinikhilReddy SrinikhilReddy changed the title Users/nanarava/multihash [Subpartitioning] SDK changes to support subpartitioning. Jun 24, 2020
@SrinikhilReddy SrinikhilReddy marked this pull request as ready for review June 24, 2020 02:05
@j82w j82w changed the title [Subpartitioning] SDK changes to support subpartitioning. Subpartitioning: Add SDK changes to support subpartitioning. Jun 24, 2020
/// Creates a new partition key value.
/// </summary>
/// <param name="value">The value to use as partition key.</param>
internal PartitionKey(object[] value)
Copy link
Contributor

@j82w j82w Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object has a lot of negative feedback considering it only supports a very few primitive types. One option is to add a PartitionKeyValue type that has implicit conversion for the supported primitive types.

@kirankumarkolli, @FabianMeiswinkel, and @ealsur do you have any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me consistency trumps everything else here - we used object for a single-value PK - so object[] is good enough for multiple.

I would also assume that this rarely results in issues with customers - at least I have ever heard of a customer trying to use a property that isn't string or numeric as the PK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with object is the chance of runtime exceptions if the actual type is not supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea (but it can cause inception issues) is to have PartitionKey(PartitionKey[] value). It can technically allow a PK that is an array to be passed as parameter to another PK constructor (array in array), but it's something the user would be actively doing. I think it boils down to reducing runtime exceptions, any check we add would generate runtime exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FabianMeiswinkel we don't use object for single-value PK. We have explicit primitives on the PartitionKey constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys, fixed as suggested.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jake for your suggestion. It looks good to me.

Copy link
Contributor

@j82w j82w Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartitionKeyBuilder pkBuilder = new PartitionKeyBuilder()
   .Add(15232)
   .Add("Pittsburgh");
                    
await container.ReadItemAsync<Document>("Id1", pkBuilder.Build())
List<PartitionKey> pKValueList = new List<PartitionKey>(){
  new PartitionKey(15232),
  new PartitionKey("Pittsburgh"),
};

Cosmos.PartitionKey pKey = new Cosmos.PartitionKey(pKValueList);
await container.ReadItemAsync<Document>("Id1", pKey)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed not to provide the List overload?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we agreed to not provide the list overload. I posted that during the meeting to show the difference. I don't see a list overload in the code.

/// Creates a new partition key value.
/// </summary>
/// <param name="value">The value to use as partition key.</param>
internal PartitionKey(object[] value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with object is the chance of runtime exceptions if the actual type is not supported.

/// Creates a new partition key value.
/// </summary>
/// <param name="value">The value to use as partition key.</param>
internal PartitionKey(object[] value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea (but it can cause inception issues) is to have PartitionKey(PartitionKey[] value). It can technically allow a PK that is an array to be passed as parameter to another PK constructor (array in array), but it's something the user would be actively doing. I think it boils down to reducing runtime exceptions, any check we add would generate runtime exceptions.

@SrinikhilReddy SrinikhilReddy requested review from ealsur and j82w June 26, 2020 04:59
@abhijitpai abhijitpai self-requested a review July 30, 2020 17:37
abhijitpai
abhijitpai previously approved these changes Jul 30, 2020
j82w
j82w previously approved these changes Jul 30, 2020
@j82w
Copy link
Contributor

j82w commented Jul 30, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@SrinikhilReddy SrinikhilReddy dismissed stale reviews from j82w, kirankumarkolli, and abhijitpai via e1d2a85 July 30, 2020 18:56
@SrinikhilReddy
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 1658 in repo Azure/azure-cosmos-dotnet-v3

@j82w
Copy link
Contributor

j82w commented Jul 31, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@j82w j82w changed the title Subpartitioning: Add SDK changes to support subpartitioning. [Internal] Subpartitioning: Adds SDK changes to support subpartitioning. Jul 31, 2020
@j82w j82w merged commit 9a75373 into Azure:master Jul 31, 2020
@ghost
Copy link

ghost commented Dec 15, 2021

Closing due to in-activity, pease feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants