-
Notifications
You must be signed in to change notification settings - Fork 12
Introduce batch support. #136
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
Conversation
|
There is an existing patch(es) for this commit SHA: Please note that the status that is posted is not in the context of this PR but rather the (latest) existing patch and that may affect some tests that may depend on the particular PR. If your tests do not rely on any PR-specific values (like base or head branch name) then your tests will report the same status. If you would like a patch to run in the context of this PR and abort the other(s), comment 'evergreen retry'. |
| @Override | ||
| public void addBatch(String mql) throws SQLException { | ||
| checkClosed(); | ||
| throw new SQLFeatureNotSupportedException("TODO-HIBERNATE-35 https://jira.mongodb.org/browse/HIBERNATE-35"); | ||
| } | ||
|
|
||
| @Override | ||
| public void clearBatch() throws SQLException { | ||
| checkClosed(); | ||
| throw new SQLFeatureNotSupportedException("TODO-HIBERNATE-35 https://jira.mongodb.org/browse/HIBERNATE-35"); | ||
| } | ||
|
|
||
| @Override | ||
| public int[] executeBatch() throws SQLException { | ||
| checkClosed(); | ||
| closeLastOpenResultSet(); | ||
| throw new SQLFeatureNotSupportedException("TODO-HIBERNATE-35 https://jira.mongodb.org/browse/HIBERNATE-35"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not implemented because Hibernate relies on PreparedStatement methods for batching.
|
Let's remove Update: we decided to leave it, as removing it causes code restructuring (otherwise the code looks weird), and we don't want to do that. Continue having this method seems to be a lesser burden than removing it. |
src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java
Outdated
Show resolved
Hide resolved
src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java
Outdated
Show resolved
Hide resolved
src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java
Outdated
Show resolved
Hide resolved
|
|
||
| @ParameterizedTest(name = "test not supported update elements. Parameters: option={0}") | ||
| @ValueSource(strings = {"hint", "collation", "arrayFilters", "sort", "upsert", "c"}) | ||
| void testNotSupportedUpdateElements(String unsupportedElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not called "element", they are called "option". See https://www.mongodb.com/docs/manual/reference/command/update/. Let's make all the changes needed to reflect that.
The same applies to testNotSupportedDeleteElements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed during the walkthrough - renamed to "field".
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported update elements. Parameters: option={0}") | ||
| @ValueSource(strings = {"hint", "collation", "arrayFilters", "sort", "upsert", "c"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect, we should use both keys and values, like "hint: 'abc'", here, as otherwise the { _id: 1 } value currently used as the value of each option is not always valid. If we use a valid value for each option, then having an exception makes it more clear the the option name itself caused it.
The same applies to testNotSupportedDeleteElements.
…redStatementIntegrationTests.java Co-authored-by: Valentin Kovalenko <[email protected]>
…redStatementIntegrationTests.java Co-authored-by: Valentin Kovalenko <[email protected]>
…redStatementIntegrationTests.java Co-authored-by: Valentin Kovalenko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished reviewing MongoPreparedStatementIntegrationTests. So far I have the following reviewed:
AbstractQueryIntegrationTestsLimitOffsetFetchClauseIntegrationTestsBatchUpdateIntegrationTestsMongoPreparedStatementIntegrationTests
We worked thoroughly on MongoPreparedStatement, MongoStatement during the code walkthrough. But I will still need to look at them once the changes are pushed.
The last reviewed commit is 11a2b07.
| .returns(0, BatchUpdateException::getErrorCode); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this catch (SQLException e) here and in any other test in ExecuteBatchTests.
Pre-existing test methods need it because they implement Function, while the new tests implement Work, and its Work.execute method throws SQLException.
src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java
Show resolved
Hide resolved
|
|
||
| @Test | ||
| void testBatchInsert() { | ||
| var batchCount = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's call it batchSize here and in other places? Feels more natural, and is closer to hibernate.jdbc.batch_size, which has the same meaning.
Neither JDBC API documentation, nor the JDBC specification seem to use "count" to refer to the number of commands in a batch.
| for (int i = 0; i < batchCount; i++) { | ||
| expectedDocs.add(BsonDocument.parse(format( | ||
| """ | ||
| { | ||
| "_id": %d, | ||
| "title": "Book %d" | ||
| }""", | ||
| i + 1, i + 1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use for (int i = 1; i <= batchCount; i++), especially given that above we used these exact boundaries, so that we could use i, i instead of i + 1, i + 1. The same suggestion applies to testBatchUpdate.
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Test statement’s batch queue is reset once executeBatch returns") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API documentation of PreparedStatement.addBatch calls it "batch of commands". I found "qeue" neither in the API documentation nor in the JDBC specification. Unless I missed it, and "queue" is the term that is actually used, let's say either "statement’s batch" or "statement's batch of commands".
…redStatementIntegrationTests.java Co-authored-by: Valentin Kovalenko <[email protected]>
Remove redundant tests.
# Conflicts: # src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java # src/test/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementTests.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java
Outdated
Show resolved
Hide resolved
src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java
Outdated
Show resolved
Hide resolved
src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Valentin Kovalenko <[email protected]>
Co-authored-by: Valentin Kovalenko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost done, but some more review work (or, rather, trying and maybe proposing) is needed in the area of exception handling and transaction handling. I continue reviewing.
src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java
Outdated
Show resolved
Hide resolved
| private static final Set<String> SUPPORTED_INSERT_COMMAND_FIELDS = Set.of("documents"); | ||
|
|
||
| private static final Set<String> SUPPORTED_UPDATE_COMMAND_FIELDS = Set.of("updates"); | ||
| private static final Set<String> SUPPORTED_UPDATE_STATEMENT_FIELDS = Set.of("q", "u", "multi"); | ||
|
|
||
| private static final Set<String> SUPPORTED_DELETE_COMMAND_FIELDS = Set.of("deletes"); | ||
| private static final Set<String> SUPPORTED_DELETE_STATEMENT_FIELDS = Set.of("q", "limit"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional]
What do you think about moving these to CommandDescription? That way the information tightly related to commands stays mostly there.
P.S. At first I thought about moving them there as instance methods, potentially with the checks, but then I realized that different commands have different structure (for example, aggregate does not have statements), which makes such endeavour non-trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Valentin Kovalenko <[email protected]>
# Conflicts: # src/main/java/com/mongodb/hibernate/jdbc/MongoStatement.java
… methods package-private.
…t.java Co-authored-by: Valentin Kovalenko <[email protected]>
Co-authored-by: Valentin Kovalenko <[email protected]>
Co-authored-by: Valentin Kovalenko <[email protected]>
Co-authored-by: Valentin Kovalenko <[email protected]>
https://jira.mongodb.org/browse/HIBERNATE-40
https://jira.mongodb.org/browse/HIBERNATE-35