feat: changes for supporting DML with Returning#1914
feat: changes for supporting DML with Returning#1914rajatbhatta wants to merge 14 commits intogoogleapis:mainfrom
Conversation
- call executeQuery for both Query and Update
statements.
- allow executeQuery to execute all Update
statements.
SingleUseTransaction
|
@rajatbhatta : Is this PR still up to date, if not,should we close it? |
| options); | ||
| case QUERY: | ||
| case UPDATE: | ||
| return internalExecuteQueryAsync(parsedStatement, analyzeMode, options); |
There was a problem hiding this comment.
I think this also needs checks to verify that the result of the statement actually contains results and not just an update count.
| "Statement is not an normal DML statement: " | ||
| + parsedStatement.getSqlWithoutComments()); | ||
| } | ||
| while (rs.next()) ; |
There was a problem hiding this comment.
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.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java
Outdated
Show resolved
Hide resolved
| return executeStatementAsync( | ||
| update, | ||
| callable, | ||
| ImmutableList.of(SpannerGrpc.getExecuteSqlMethod(), SpannerGrpc.getCommitMethod())); |
There was a problem hiding this comment.
Hmm.... This is going to be a little bit of a difficult decision:
executeUpdateused to use theexecuteSqlmethod, whileexecuteQueryused theexecuteStreamingSql. Now all statements will useexecuteStreamingSql.- 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.
- So users who currently set a timeout value for
ExecuteSqlwill now have to set a timeout value forExecuteStreamingSql.
It also means that we need to replace all references to SpannerGrpc.getExecuteSqlMethod() with SpannerGrpc.getExecuteStreamingSqlMethod().
There was a problem hiding this comment.
Replaced all references of SpannerGrpc.getExecuteSqlMethod() with SpannerGrpc.getExecuteStreamingSqlMethod().
google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java
Outdated
Show resolved
Hide resolved
| String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, ""); | ||
| // String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, ""); | ||
| String instanceProperty = "projects/span-cloud-testing/instances/rajatrb-test-instance"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Does this mean that we don't support RETURNING for batch DML?
| } | ||
|
|
||
| @Test | ||
| public void testExecuteInvalidQueryAsync() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Reinstated the test with small change in when the exception will be raised.
| default: | ||
| } | ||
| } | ||
| ResultSet rs = internalExecuteQuery(parsedStatement, AnalyzeMode.NONE); |
There was a problem hiding this comment.
- 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?
There was a problem hiding this comment.
Have added tests for these scenarios.
| } | ||
| switch (parsedStatement.getType()) { | ||
| case UPDATE: | ||
| return internalExecuteUpdateAsync(parsedStatement); |
There was a problem hiding this comment.
What happens if this is called with a DML statement with a RETURNING clause?
…nnection/ConnectionImpl.java Co-authored-by: Knut Olav Løite <[email protected]>
|
Closing this PR in favour of #1978. |
call executeQuery for both Query and Update
statements.
allow executeQuery to execute all Update
statements.