Commit e076d87
authored
Cosmos DB: Adds Patch Support (#2161)
## Why make this change?
Today, in cosmos DB, we have ability to `update` the item which is
actually `replace` the item. Adding new operation i.e. `patch` where
customer would have ability to "patch" an item.
`PATCH` would be available only for Cosmos DB.
## What is this change?
Before going further, it is highly recommended to go through below docs:
1. How patch works in Cosmos DB
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update#supported-operations
2. Limitations:
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update#supported-modes
3. How it works with SDK:
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update-getting-started?tabs=dotnet#prerequisites
To Summarize, here is a simple example of patch:
```
List<PatchOperation> operations = new ()
{
PatchOperation.Add("/color", "silver"),
PatchOperation.Remove("/used"),
PatchOperation.Increment("/price", 50.00),
PatchOperation.Add("/tags/-", "featured-bikes")
};
ItemResponse<Product> response = await container.PatchItemAsync<Product>(
id: "e379aea5-63f5-4623-9a9b-4cd9b33b91d5",
partitionKey: new PartitionKey("road-bikes"),
patchOperations: operations
);
```
You need to generate `PatchOpertation` which need below information:
a) Operation type i.e. Set, Add, Remove etc
b) Attribute Path where operation needs to be applied i.e "/color",
"/used" in above example
c) New value
**What DAB supports?**
1. We decided to support only `Set` operation, as it solves the purpose
to update an item. It means, you cannot perform any specific operations
like remove, move etc.
2. There is no special handling for an array.
3. If the target path specifies an element that doesn't exist, it's
added.
4. If the target path specifies an element that already exists, its
value is replaced.
**Changes as part of this PR:**
1. Generate `patch` operation for given entities

5. Generate `PatchPlanetInput` without _id_ field as using patch
operation you can not update an `Id`

6. Implement patch operation
a) It translates the passed item into "patchoperation" by traversing the
item.
b) Checks if number of patch operations are less than 10 or more than 10
(as cosmsodb supports at max 10 patch operations at a time)
c) If it is less than or equal to 10, it fires patch call with patch
operations
d) If it is greater than 10, then it creates a transaction batch of
patch call, with 10 patch operations in each patch call. (_RU exhaustive
but functionally it works_)
**Pictorial Overview of the implementation**
```mermaid
flowchart TD
User[fa:fa-user User]-->| patch operation |DAB
subgraph DAB[DAB]
Authorization[Authorization]-->Patch
subgraph Patch[Patch Operation]
PatchOperation[Generate Patch 'Set' Operations with passed item] -->CheckCount{Number of Patch Operation > 10}
CheckCount --> |No| SDKOperation[SDK Patch call]
CheckCount --> |Yes| TransactionBatch[Create a batch of patch calls with max 10 patch operations ]-->SDKBatchOperation[SDK ExecuteBatch call]
end
end
```
## How was this tested?
- [ ] Integration Tests
- [ ] Unit Tests
## Sample Request(s)
- Example REST and/or GraphQL request to demonstrate modifications
- Example of CLI usage to demonstrate modifications1 parent d2aa5aa commit e076d87
File tree
12 files changed
+738
-109
lines changed- src
- Config/ObjectModel
- Core
- Configurations
- Resolvers
- Sql Query Structures
- Services
- Service.GraphQLBuilder/Mutations
- Service.Tests
- Configuration
- CosmosTests
- GraphQLBuilder
- Unittests
12 files changed
+738
-109
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
151 | | - | |
| 154 | + | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
324 | | - | |
| 325 | + | |
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
| |||
345 | 346 | | |
346 | 347 | | |
347 | 348 | | |
348 | | - | |
| 349 | + | |
| 350 | + | |
349 | 351 | | |
350 | 352 | | |
351 | 353 | | |
| |||
356 | 358 | | |
357 | 359 | | |
358 | 360 | | |
| 361 | + | |
359 | 362 | | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
363 | 366 | | |
364 | | - | |
| 367 | + | |
| 368 | + | |
365 | 369 | | |
366 | 370 | | |
367 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
68 | | - | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
| |||
88 | 100 | | |
89 | 101 | | |
90 | 102 | | |
91 | | - | |
| 103 | + | |
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
| |||
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
115 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
116 | 136 | | |
117 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
118 | 141 | | |
119 | 142 | | |
120 | 143 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
| |||
234 | 257 | | |
235 | 258 | | |
236 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
237 | 368 | | |
238 | 369 | | |
239 | 370 | | |
| |||
270 | 401 | | |
271 | 402 | | |
272 | 403 | | |
273 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
274 | 417 | | |
275 | 418 | | |
276 | 419 | | |
277 | 420 | | |
278 | 421 | | |
279 | 422 | | |
280 | 423 | | |
281 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
282 | 435 | | |
283 | 436 | | |
284 | 437 | | |
| |||
287 | 440 | | |
288 | 441 | | |
289 | 442 | | |
290 | | - | |
| 443 | + | |
291 | 444 | | |
292 | 445 | | |
293 | 446 | | |
294 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
295 | 455 | | |
296 | 456 | | |
297 | | - | |
| 457 | + | |
298 | 458 | | |
299 | 459 | | |
300 | 460 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
0 commit comments