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

Inserting Flux of Items Inserts Only One Item When Retrieving the Number of Rows Updated #374

Closed
TheNumberOne opened this issue May 25, 2020 · 6 comments
Labels
status: invalid An issue that we don't feel is valid type: task A general task

Comments

@TheNumberOne
Copy link

This is caused by line
https://github.com/spring-projects/spring-data-r2dbc/blob/master/src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java#L1162.

Line
return Mono.from(objectToInsert).flatMapMany(toInsert -> exchange(toInsert, mappingFunction).rowsUpdated()) .collect(Collectors.summingInt(Integer::intValue));
should be
return Flux.from(objectToInsert).flatMapMany(toInsert -> exchange(toInsert, mappingFunction).rowsUpdated()) .collect(Collectors.summingInt(Integer::intValue));

I can create an example project showing this error and submit a pull request with a fix if you wish.

@TheNumberOne
Copy link
Author

Here is a minimal repository with the failing code in the test:
https://github.com/TheNumberOne/spring-data-r2dbc-insert-bug

@mp911de
Copy link
Member

mp911de commented May 26, 2020

Feel free to submit a pull request.

Please note that our DatabaseClient is going to be deprecated once the Spring R2DBC pull request gets merged. You might want to have a look at ReactiveInsertOperation as well.

@mp911de mp911de added the type: task A general task label May 26, 2020
@m1ngyuan
Copy link
Contributor

m1ngyuan commented May 26, 2020

@mp911de
Is there a best practice for bulk entity insertion? , r2dbc SPI defines io.r2 dbc.spi.Connection#createBatch , can it be supported in databaseclient

@mp911de
Copy link
Member

mp911de commented May 26, 2020

R2DBC's Batch is a batch of unparametrized statements. This type of batch uses parametrized statements so the way to go should be Statement.add(). Since DatabaseClient does not yet expose functionality for batching, we need to create and issue individual statements.

@TheNumberOne
Copy link
Author

TheNumberOne commented May 26, 2020

Actually, I wasn't able to get the project to build fully on my machine (had a couple failing integration tests.) Do you have any advice for that? Also, thanks for letting me know it will be deprecated. What database client is it being replaced with?

@mp911de
Copy link
Member

mp911de commented Jul 23, 2020

Superseded by #368. We should reconsider batching with #259.

@mp911de mp911de closed this as completed Jul 23, 2020
@mp911de mp911de added the status: invalid An issue that we don't feel is valid label Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid type: task A general task
Projects
None yet
Development

No branches or pull requests

3 participants