azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

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

Open luczsoma opened this issue 3 years ago • 1 comments

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

  • [x] Description Added
  • [x] Expected solution specified

luczsoma avatar Apr 11 '21 15:04 luczsoma

@kushagraThapar PTAL

joshfree avatar Apr 12 '21 17:04 joshfree

Considering this for next semester planning.

TheovanKraay avatar Aug 16 '23 19:08 TheovanKraay

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

kushagraThapar avatar Jan 23 '24 18:01 kushagraThapar

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.

github-actions[bot] avatar Apr 08 '24 18:04 github-actions[bot]