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

Batch DML support #107

Merged
merged 3 commits into from
Jun 11, 2019
Merged

Batch DML support #107

merged 3 commits into from
Jun 11, 2019

Conversation

dmitry-s
Copy link
Contributor

fixes #92

…-r2dbc into batch-dml

# Conflicts:
#	src/main/java/com/google/cloud/spanner/r2dbc/SpannerStatement.java
#	src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerIT.java
@dmitry-s dmitry-s requested review from elefeint, meltsufin, dzou and ChengyuanZhao and removed request for elefeint and meltsufin June 10, 2019 19:23
Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just need to switch to a unary call (good to know that it works with streaming; we've built resilient conversion between grpc and publishers, I guess).

PartialResultRowExtractor partialResultRowExtractor = new PartialResultRowExtractor();

Flux<PartialResultSet> resultSetFlux =
this.client.executeStreamingSql(
this.session, this.transaction, this.sql, params, this.statementBindings.getTypes());

if (statementType == StatementType.SELECT) {
if (this.statementType == StatementType.SELECT) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this check anymore? DML does not go through this method anymore, and I don't imagine DDL will either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 and should probably rename to runSelectStatement

}

return ObservableReactiveUtil
.streamingCall(obs -> this.spanner.executeBatchDml(request.build(), obs));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a streaming call; use unaryCall() here.

@@ -268,12 +292,13 @@ public void testEmptySelect() {
/**
* Executes a DML query and returns the rows updated.
*/
private int executeDmlQuery(String sql) {
private List<Integer> executeDmlQuery(String sql) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be kept as before, returning integer? B/c String sql can only correspond to one statement.


if (statementType == StatementType.SELECT) {
return structFlux.flatMap(struct -> runSingleStatement(struct, statementType));
if (this.statementType == StatementType.DML) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you should just have a class hierarchy of statements -- SpannerDmlStatement, SpannerDdlStatement, SpannerReadStatement. WDYT?

}
// DML statements have to be executed sequentially because they need seqNo to be in order
return structFlux.concatMapDelayError(struct -> runSingleStatement(struct, statementType));
Flux<Struct> structFlux = Flux.fromIterable(this.statementBindings.getBindings());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Else if SELECT? Are you missing the DDL case?
The whole thing cloud be a switch statement, with the default throwing an exception.
Alternatively, see my suggestion about the class hierarchy.

PartialResultRowExtractor partialResultRowExtractor = new PartialResultRowExtractor();

Flux<PartialResultSet> resultSetFlux =
this.client.executeStreamingSql(
this.session, this.transaction, this.sql, params, this.statementBindings.getTypes());

if (statementType == StatementType.SELECT) {
if (this.statementType == StatementType.SELECT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 and should probably rename to runSelectStatement

Connection connection = Mono.from(connectionFactory.create()).block();

Mono.from(connection.beginTransaction()).block();
int rowsUpdated = Mono.from(connection.createStatement(sql).execute())
List<Integer> rowsUpdated = Flux.from(connection.createStatement(sql).execute())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/rowsUpdated/rowsUpdatedPerStatement

@dmitry-s dmitry-s merged commit 3aa0278 into master Jun 11, 2019
@elefeint elefeint deleted the batch-dml branch November 4, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Natively support multiple DML statements
4 participants