Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

feat: changes for supporting DML with Returning#1914

Closed
rajatbhatta wants to merge 14 commits intogoogleapis:mainfrom
rajatbhatta:dml-returning-changes
Closed

feat: changes for supporting DML with Returning#1914
rajatbhatta wants to merge 14 commits intogoogleapis:mainfrom
rajatbhatta:dml-returning-changes

Conversation

@rajatbhatta
Copy link
Copy Markdown
Contributor

  • call executeQuery for both Query and Update
    statements.

  • allow executeQuery to execute all Update
    statements.

-   call executeQuery for both Query and Update
    statements.

-   allow executeQuery to execute all Update
    statements.
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/java-spanner API. labels Jun 10, 2022
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Jun 10, 2022
@ansh0l
Copy link
Copy Markdown
Contributor

ansh0l commented Jul 4, 2022

@rajatbhatta : Is this PR still up to date, if not,should we close it?

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jul 18, 2022
options);
case QUERY:
case UPDATE:
return internalExecuteQueryAsync(parsedStatement, analyzeMode, options);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this also needs checks to verify that the result of the statement actually contains results and not just an update count.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

"Statement is not an normal DML statement: "
+ parsedStatement.getSqlWithoutComments());
}
while (rs.next()) ;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should add a comment to explain why we are doing this. Also, according to the Google style guide, a while statement must have curly braces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

return executeStatementAsync(
update,
callable,
ImmutableList.of(SpannerGrpc.getExecuteSqlMethod(), SpannerGrpc.getCommitMethod()));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm.... This is going to be a little bit of a difficult decision:

  1. executeUpdate used to use the executeSql method, while executeQuery used the executeStreamingSql. Now all statements will use executeStreamingSql.
  2. Users can set custom timeout and retry settings per RPC. This meant that they previously could in theory set a different timeout value for queries and DML statements. That is no longer possible, as they use the same RPC.
  3. So users who currently set a timeout value for ExecuteSql will now have to set a timeout value for ExecuteStreamingSql.

It also means that we need to replace all references to SpannerGrpc.getExecuteSqlMethod() with SpannerGrpc.getExecuteStreamingSqlMethod().

Copy link
Copy Markdown
Contributor Author

@rajatbhatta rajatbhatta Aug 2, 2022

Choose a reason for hiding this comment

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

Replaced all references of SpannerGrpc.getExecuteSqlMethod() with SpannerGrpc.getExecuteStreamingSqlMethod().

Comment on lines -85 to +86
String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, "");
// String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, "");
String instanceProperty = "projects/span-cloud-testing/instances/rajatrb-test-instance";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here also: remove commented code

.asRuntimeException();
// Check if result containing UPDATE_COUNT exists. If not, throw an exception.
res = getResult(spannerStatement, StatementResult.StatementResultType.UPDATE_COUNT);
if (res == null) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this mean that we don't support RETURNING for batch DML?

}

@Test
public void testExecuteInvalidQueryAsync() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this test case removed? If I understand it correctly, this would execute a DML statement without a returning clause, which means that it should still fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reinstated the test with small change in when the exception will be raised.

default:
}
}
ResultSet rs = internalExecuteQuery(parsedStatement, AnalyzeMode.NONE);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • What happens if this is called while the connection is in read-only mode?
  • What happens if this is called while a read-only transaction is active?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have added tests for these scenarios.

}
switch (parsedStatement.getType()) {
case UPDATE:
return internalExecuteUpdateAsync(parsedStatement);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens if this is called with a DML statement with a RETURNING clause?

@rajatbhatta
Copy link
Copy Markdown
Contributor Author

Closing this PR in favour of #1978.

@rajatbhatta rajatbhatta deleted the dml-returning-changes branch August 22, 2022 18:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants