mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-04-18 12:29:48 +01:00
Handle partition key path with whitespace (#2423)
* Handle partition key path with white space * add whitespace test case for pkey * remove trailing whitespace --------- Co-authored-by: Asier Isayas <aisayas@microsoft.com>
This commit is contained in:
@@ -350,6 +350,25 @@ describe("Query Utils", () => {
|
|||||||
expect(partitionKeyValues.length).toBe(2);
|
expect(partitionKeyValues.length).toBe(2);
|
||||||
expect(partitionKeyValues).toEqual(["Japan", "hello"]);
|
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", () => {
|
describe("stripDoubleQuotesFromSegment", () => {
|
||||||
|
|||||||
@@ -157,7 +157,11 @@ export const extractPartitionKeyValues = (
|
|||||||
const partitionKeyValues: PartitionKey[] = [];
|
const partitionKeyValues: PartitionKey[] = [];
|
||||||
|
|
||||||
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
|
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);
|
const value = getValueForPath(documentContent, pathSegments);
|
||||||
|
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
|
|||||||
@@ -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: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user