ballerina-library icon indicating copy to clipboard operation
ballerina-library copied to clipboard

[Feature]: Include PATCH document operation to the connector

Open sachinira opened this issue 1 year ago • 7 comments

Connector Name

module/cosmosdb (Cosmos DB)

Suggested feature

The patch methods are not implemented in the connector, but are available in the CosmosDB API: https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document.

The "PATCH" operation allows to make partial updates to a document by specifying only the fields you want to change, leaving the rest of the document intact. This can be useful when we have a large document and only want to modify a few fields. The "PATCH" operation is also known as the "Partial Update" operation. Implement Patch Document method to include the document patch functionality to the connector

Discord : https://discord.com/channels/957996897782616114/1137459261551689861/1137459261551689861

Related issues

No response

sachinira avatar Aug 07 '23 07:08 sachinira

Hi,

I'd like to work on this issue.

ImeshBalasuriya avatar Oct 03 '23 10:10 ImeshBalasuriya

My proposed solution for this is to include a new API with the following function signature.

remote isolated function patchDocument(string databaseId, string containerId, string documentId, PatchOperation[] operations, int|float|decimal|string partitionKey, PatchRequestOptions? requestOptions = ()) returns DocumentResponse|error { }

The PatchOperation record type can be defined as follows along with an enum to limit the op field to the patch operations supported by the CosmosDB API.

public type PatchOperation record {
   OperationType op;
   string path;
   anydata value;
};

enum OperationType {
   ADD_PATCH_OPERATION = "add",
   SET_PATCH_OPERATION = "set",
   REPLACE_PATCH_OPERATION = "replace",
   REMOVE_PATCH_OPERATION = "remove",
   INCREMENT_PATCH_OPERATION = "increment",
   MOVE_PATCH_OPERATION = "move"
}

Please let me know your thoughts on this. Thanks!

ImeshBalasuriya avatar Oct 05 '23 07:10 ImeshBalasuriya

Hi,

Any updates on this? 👀

ImeshBalasuriya avatar Oct 09 '23 11:10 ImeshBalasuriya

Hi @ImeshBalasuriya ,

The solution seems fine with some adjustments

  • As there are no requestOptions for patch operations (In the doc) we can remove this param
  • There is a capability called Conditional Patch operation which is not covered in this solution

Can improve the solution with these and you are good to go !!

Note

  • Cosmos DB connector internally uses Cosmos DB Java SDK and you may have to use that too in this implementation (Version 4.48.1)

sachinira avatar Oct 09 '23 12:10 sachinira

Hi @sachinira,

Thanks for the response!

The requestOptions optional parameter is a record of type PatchRequestOptions which contains a string field filterPredicate that implements the Conditional Patch feature. This is in line with the Java SDK where an overloaded patchItem() method contains a parameter of the same name.

Given that this addresses the second adjustment mentioned as well, I hope it is okay to proceed with the implementation as is.

ImeshBalasuriya avatar Oct 09 '23 13:10 ImeshBalasuriya

@ImeshBalasuriya are you still working on this issue?

keizer619 avatar Nov 16 '23 08:11 keizer619

Hu @keizer619,

Unfortunately, I'm a bit busy atm. If the feature is urgent, please feel free to reassign the issue. If not, I am happy to continue work on it once I am free.

ImeshBalasuriya avatar Nov 16 '23 10:11 ImeshBalasuriya

Can I work on this issue?

Atharva1723 avatar Oct 06 '24 09:10 Atharva1723