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

[Feature]: Include PATCH document operation to the connector #4972

Closed
sachinira opened this issue Aug 7, 2023 · 9 comments · Fixed by ballerina-platform/module-ballerinax-azure-cosmosdb#115

Comments

@sachinira
Copy link

sachinira commented Aug 7, 2023

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

@ImeshBalasuriya
Copy link

Hi,

I'd like to work on this issue.

@ImeshBalasuriya
Copy link

ImeshBalasuriya commented Oct 5, 2023

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
Copy link

Hi,

Any updates on this? 👀

@sachinira
Copy link
Author

sachinira commented Oct 9, 2023

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)

@ImeshBalasuriya
Copy link

ImeshBalasuriya commented Oct 9, 2023

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.

@ayeshLK ayeshLK transferred this issue from ballerina-attic/ballerina-extended-library Oct 17, 2023
@keizer619 keizer619 moved this from In Progress to Todo in Hacktoberfest 2023 Nov 16, 2023
@keizer619
Copy link
Member

@ImeshBalasuriya are you still working on this issue?

@ImeshBalasuriya
Copy link

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.

@Atharva1723
Copy link

Can I work on this issue?

@NipunaRanasinghe
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants