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

feat: changes for supporting DML with Returning #1914

Closed
wants to merge 14 commits into from

Conversation

rajatbhatta
Copy link
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
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
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
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
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
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
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
Contributor Author

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
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
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?

@@ -390,18 +397,6 @@ public void testExecuteClientSideQueryAsync() {
}
}

@Test
public void testExecuteInvalidQueryAsync() {
Copy link
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
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
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
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
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
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 join this conversation on GitHub. Already have an account? Sign in to comment
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.

None yet

3 participants