Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.34k stars 1.98k forks source link

[FEATURE REQ] PK-based findAllById + deleteAllById methods in CosmosRepository #20529

Open luczsoma opened 3 years ago

luczsoma commented 3 years ago

Is your feature request related to a problem? Please describe. Looking up or deleting multiple items with CosmosRepository (of azure-spring-data-cosmos) cannot be done without fan-out queries, in one step (as one query).

Describe the solution you'd like CosmosRepository has findById and deleteById overrides having PartitionKey as their 2nd parameter, enabling efficient, in-partition queries. There could be findAllById and deleteAllById overrides as well with a PartitionKey parameters, enabling lookups/deletes of multiple items within one partition, e.g.:

Iterable<T> findAllById(Iterable<ID> ids, PartitionKey pk);
void deleteAllById(Iterable<ID> ids, PartitionKey pk);

The method findAllById(Iterable<ID> ids, PartitionKey pk) would initiate a findAllById search, but only within the partition specified by pk, and return the found items. If no items were found with the given ids in the partition specified by pk, the returned list would be empty. If no partition exists with the key pk, the returned list would be empty. (Implicitly, if an item with the specified ID can not be found in the given partition, but can be found in another partition, the result will not contain the item.)

Similarly, the method deleteAllById(Iterable<ID> ids, PartitionKey pk) would initiate a deleteAllById, but only within the partition specified by pk. If no items were found with the given ids in the partition specified by pk, the method would return regularly. If no partition exists with the key pk, the method would return regularly. (Implicitly, if an item with the specified ID can not be found in the given partition, but can be found in another partition, it won't be deleted.)

Describe alternatives you've considered The alternatives for solving the multi-lookup problem are either calling findAllById(Iterable<ID> ids) (but this is a fan-out query, which is AFAIK very inefficient in Cosmos), or calling findById(ID id, PartitionKey pk) multiple times. Both solutions are inefficient. The same problem exists for deleting.

Additional context

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

joshfree commented 3 years ago

@kushagraThapar PTAL

TheovanKraay commented 1 year ago

Considering this for next semester planning.

kushagraThapar commented 9 months ago

@TheovanKraay please take a look at this issue, thanks!

github-actions[bot] commented 6 months ago

Hi @luczsoma, we deeply appreciate your input into this project. Regrettably, this issue has remained inactive for over 2 years, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

kushagraThapar commented 1 month ago

@luczsoma we discussed about this and the recommendation from spring team is to not include more custom methods in the spring data cosmos - CosmosRepository. I will recommend using the CosmosClient which gets created in spring data cosmos SDK under the hood and you should be able to use this API - readMany - https://learn.microsoft.com/en-us/java/api/com.azure.cosmos.cosmosasynccontainer?view=azure-java-stable#com-azure-cosmos-cosmosasynccontainer-(t)readmany(java-util-list(com-azure-cosmos-models-cosmositemidentity)-com-azure-cosmos-models-cosmosreadmanyrequestoptions-java-lang-class(t))