Compare commits

...

3 Commits

Author SHA1 Message Date
asier-isayas
b3f7e280ca Merge branch 'master' into users/aisayas/pkey-whitespace 2026-03-11 09:11:32 -07:00
Asier Isayas
924f03df74 add whitespace test case for pkey 2026-03-11 09:10:57 -07:00
Asier Isayas
aeb3537a68 Handle partition key path with white space 2026-03-11 07:11:35 -07:00
3 changed files with 47 additions and 1 deletions

View File

@@ -350,6 +350,25 @@ describe("Query Utils", () => {
expect(partitionKeyValues.length).toBe(2);
expect(partitionKeyValues).toEqual(["Japan", "hello"]);
});
it("should extract partition key value when path has surrounding whitespace", () => {
const doc = {
id: "test-id",
Country: "United States",
Location: {
type: "Point",
},
};
const partitionKeyDefinition: PartitionKeyDefinition = {
kind: PartitionKeyKind.MultiHash,
paths: ["/ Country ", "/ Location / type "],
};
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(doc, partitionKeyDefinition);
expect(partitionKeyValues.length).toBe(2);
expect(partitionKeyValues).toEqual(["United States", "Point"]);
});
});
describe("stripDoubleQuotesFromSegment", () => {

View File

@@ -157,7 +157,11 @@ export const extractPartitionKeyValues = (
const partitionKeyValues: PartitionKey[] = [];
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
const pathSegments: string[] = partitionKeyPath.substring(1).split("/").map(stripDoubleQuotesFromSegment);
const pathSegments: string[] = partitionKeyPath
.substring(1)
.split("/")
.map(stripDoubleQuotesFromSegment)
.map((s) => s.trim());
const value = getValueForPath(documentContent, pathSegments);
if (value !== undefined) {

View File

@@ -272,4 +272,27 @@ export const documentTestCases: DocumentTestCase[] = [
},
],
},
{
name: "Single Partition Key With Whitespace",
databaseId: "e2etests-sql-readonly",
containerId: "whitespacePartitionKey",
documents: [
{
documentId: "whitespacePartitionKey",
partitionKeys: [{ key: "/ partitionKey ", value: "whitespaceValue" }],
},
{
documentId: "whitespacePartitionKey_empty_string",
partitionKeys: [{ key: "/ partitionKey ", value: "" }],
},
{
documentId: "whitespacePartitionKey_null",
partitionKeys: [{ key: "/ partitionKey ", value: null }],
},
{
documentId: "whitespacePartitionKey_missing",
partitionKeys: [],
},
],
},
];