Single result queries#480
Conversation
|
@Blackbaud-MikeLueders Thanks for opening this PR. I will take a look at it.
|
|
@kushagraThapar this PR actually contains two separate changes, one is the feature change described in the summary and the other is to update the integration tests to respect cosmos.database if set. Would you prefer I split these changes into two separate PRs? |
Yes, I was about to comment that, specially after your last commit :) |
992269d to
7d86cc3
Compare
|
@kushagraThapar I've split out the test updates to #482 |
Thanks for splitting it out, I will look at all 3 PRs soon. |
|
/azp run |
|
No pipelines are associated with this pull request. |
kushagraThapar
left a comment
There was a problem hiding this comment.
Can you please add some example / test case for ReactiveCosmosRepository as well ?
@Blackbaud-MikeLueders I also looked at your statement regarding findbyId(id, partitionKey) -> returning List internally. |
7d86cc3 to
c869f35
Compare
|
@kushagraThapar you're right, findById seems to be special in that it uses a different execution path than a regular query. I've separated the changes in this branch to two commits - the first is the integration test These are valid Spring Data methods but the tests which execute them will fail without the second commit. Any call to the first method will fail with Also, just FYI, the specific test you reference is wrong and should be failing but never will. In this instance, TEST_ADDRESS1_PARTITION1's type is Address, not Optional. Optional:equals will only return true if the object being compared is also an Optional. |
|
Issues
======
- Added 1
Complexity increasing per file
==============================
- src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/SingleResponseRepositoryIT.java 1
See the complete overview on Codacy |
|
@kushagraThapar as requested, I've added a reactive test. However, codacy is failing b/c of missing asserts. This test exactly mirrors the existing reactive tests in |
|
/azp run |
|
No pipelines are associated with this pull request. |
Thanks for pointing out the assertThat issue. I have fixed it in another PR. |
|
|
||
| Flux<Course> findByDepartmentIn(Collection<String> departments); | ||
|
|
||
| Mono<Course> findByName(String name); |
There was a problem hiding this comment.
What happens when there are multiple courses with same name ?
|
|
||
| Contact findOneByTitle(String title); | ||
|
|
||
| Optional<Contact> findOptionallyByTitle(String title); |
There was a problem hiding this comment.
Same question as below, what if there are multiple Contacts with same title ?
How would these two APIs behave (findByName and this one)..
There was a problem hiding this comment.
it will fail, as demonstrated by the test testShouldFailIfMultipleResultsReturned in the first commit. it is expected that the client understands their data model and would not add a findOneBy or findOptionallyBy for queries that could return more than one item.
| final String collection = ((CosmosEntityMetadata) method.getEntityInformation()).getCollectionName(); | ||
|
|
||
| final CosmosQueryExecution execution = getExecution(accessor); | ||
| final CosmosQueryExecution execution = getExecution(accessor, processor.getReturnedType()); |
There was a problem hiding this comment.
When I mentioned for ReactiveCosmosRepository, I actually meant to have this functionality on ReactiveQuery pipeline as well.
For example, this code needs to be updated in AbstractReactiveCosmosQuery as well.
| } | ||
| } | ||
|
|
||
| final class SingleEntityExecution implements CosmosQueryExecution { |
There was a problem hiding this comment.
Same as above comment: ReactiveCosmosQueryExecution changes ?
|
|
||
| @RunWith(SpringJUnit4ClassRunner.class) | ||
| @ContextConfiguration(classes = TestRepositoryConfig.class) | ||
| public class SingleResponseRepositoryIT { |
There was a problem hiding this comment.
It would be much better to have separate test cases for CosmosRepository and ReactiveCosmosRepository. That's the convention we follow and all the test cases have been designed like that .
|
@Blackbaud-MikeLueders Any updates on the above PR comments / feedback ? |
|
@Blackbaud-MikeLueders - We have a release scheduled for this Tuesday - 25th Feb. It would be great if we can get this in before then. Would like this feature to get in spring-data-cosmsodb - 2.2.3 release. |
|
@kushagraThapar apologies for losing track of this, we're going to pick this up in the next couple weeks and begin adding the reactive support. |
6c54615 to
0a4d7da
Compare
0a4d7da to
e6686f0
Compare
|
@Blackbaud-MikeLueders - We are currently in development of new spring-data-cosmosdb module - which will take a dependency on azure-cosmos V4 SDK (new GA SDK, which is better in terms of latency and throughput than V3 SDK). This repo has been moved to https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/cosmos/azure-spring-data-cosmosdb If you want this fix to go into the new repo, I would suggest opening this PR against the new repo. However, if you want this fix to go in earlier versions, then we can keep this fix here as it is and target it against master. |
|
@kushagraThapar thanks for the heads up, i'll go ahead and close this PR and target the new repo. What's the best way to know when the repo has been completely moved? |
|
@Blackbaud-MikeLueders - all the source code has already been merged, and samples are currently being merged. The best way to know would be me telling you :) I will update you once I have moved spring-data-cosmosdb to V4 SDK, as implementation code will change. |
|
@kushagraThapar That would be great, thank you! FYI, we have some additional changes as well
I was waiting on raising those until this PR was addressed to avoid too much at once but should we raise those items as PRs against this repo now so they can be reviewed (and we'd move them to the new repo next week) so we can bet those in as well before GA? |
|
@Blackbaud-MikeLueders Sounds good, all those features sounds cool and will be very good to have. Meanwhile, I will highly encourage you guys to go over cosmos V4 SDK changes - https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-v4 |
This is a rebase of #381, I don't have permissions to update the branch so opening this as a new PR.
@kushagraThapar would you mind taking a look? Thanks!
This PR is a feature enhancement, adding the ability to have Repository methods that return a single object or Optional. Let's say I have the following...
class Repository extends CosmosRepository {
Foo findBySomething(String something);
}
Calling this method will currently result in a ClassCastException since it assumes a return type of List.
In addition, the findById method on CosmosRepository declares the following method - Optional findById(ID id, PartitionKey partitionKey); The contract says the Optional should contain the entity type but it does not - it contains a list of entity types. I would argue that the latter is a bug since the value returned in the Optional differs from what the method says should be returned.
The workaround would be to not use any methods that returned a single entity and to cast the returned value from the Optional to a List (since the actual value and the contract value are different) and deal with the single item list.
Does this help? Let me know if you'd like additional details.