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

Heiarchical Partition Keys: Fixes bug for ReadMany where None Partition does not return results #4977

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions Microsoft.Azure.Cosmos/src/ReadManyQueryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ private QueryDefinition CreateReadManyQueryDefinitionForOther(List<(string, Part
}
for (int j = 0; j < this.partitionKeySelectors.Count; j++)
{
if (pkValues[j] == Undefined.Value)
Copy link
Member

Choose a reason for hiding this comment

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

In-general ReadMany is for many point operation reads => each partition-key should be complete/full.

Hierarchical partitions: ReadMany as name might get mis-mapped for HierarchicalParittioning, isn't the ideal solution to use regular query instead?

{
queryStringBuilder.Append(" AND ");
queryStringBuilder.Append("IS_DEFINED(c");
Copy link
Member

Choose a reason for hiding this comment

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

Clarification: Create will not work if any of the partition-keys are not defined right?
Can we please check this with query team.

Copy link
Member

Choose a reason for hiding this comment

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

Can this clause it-self be excluded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create will be able to work with null as the secondary partition key value. The problem here is that in order to do the ReadMany you will need to have a complete partition key. To do this you need to set one of the values as NoneType currently, when you do this the resulting query that the ReadMany call does results in no results. Doing a normal query where the PK is NoneType is ok, however this change was not carried over to when HPK were added

queryStringBuilder.Append(this.partitionKeySelectors[j]);
queryStringBuilder.Append(") = false");
continue;
}

queryStringBuilder.Append(" AND ");
queryStringBuilder.Append("c");
queryStringBuilder.Append(this.partitionKeySelectors[j]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,28 @@ public async Task MultiHashQueryItemTest()
}
}
}

[TestMethod]
public async Task ReadManyNullPkValueTest()
{
Document doc = new Document { Id = "readMany" };
doc.SetValue("ZipCode", "10000");

await this.container.CreateItemAsync<Document>(doc);

Cosmos.PartitionKey pk = new PartitionKeyBuilder()
.Add("10000")
.AddNoneType()
.Build();

ItemResponse<Document> ir = await this.container.ReadItemAsync<Document>("readMany", pk);
Assert.IsNotNull(ir.Resource);
Assert.AreEqual(ir.StatusCode, HttpStatusCode.OK);

FeedResponse<Document> feedResponse = await this.container.ReadManyItemsAsync<Document>(
new List<(string, Cosmos.PartitionKey)> { ("readMany", pk) });

Assert.AreEqual(1, feedResponse.Count());
}
}
}
Loading