bitflicker64 commented on code in PR #909:
URL:
https://github.com/apache/hugegraph-toolchain/pull/909#discussion_r4597773099
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/reader/jdbc/JDBCFetcher.java:
##########
@@ -132,6 +136,18 @@ public List<Line> nextBatch() throws SQLException {
return lines;
}
+ private void disableAutoCommit() {
+ try {
+ if (this.conn.getAutoCommit()) {
Review Comment:
Important: `JDBCFetcherTest.testLocalDateTimeUsesDriverTimestamp` fails on
this head with a `NullPointerException` from `getAutoCommit`, because its
`Connection` proxy returns `null` for every method other than `createStatement`
and `isClosed`, and `disableAutoCommit` catches only `SQLException`. Make the
proxy answer `getAutoCommit`, and assert that `setAutoCommit(false)` and
`setFetchSize` run before `executeQuery`.
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/reader/jdbc/JDBCFetcher.java:
##########
@@ -85,11 +85,15 @@ public void close() {
@Override
public List<Line> nextBatch() throws SQLException {
if (!start) {
+ // Some drivers (e.g. PostgreSQL) only stream rows through a
cursor when
+ // auto-commit is off and the fetch size is set before the query
runs;
+ // otherwise the whole result set is buffered in memory.
+ disableAutoCommit();
stmt =
this.conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
+ stmt.setFetchSize(source.batchSize());
Review Comment:
Important: MySQL Connector/J streams only when the fetch size is
`Integer.MIN_VALUE` or the URL sets `useCursorFetch=true`, and
`JDBCVendor.MYSQL.buildUrl` sets neither, so a fetch size of `batch_size` still
buffers the whole MySQL table. Make MySQL stream too, or scope the title and
commit message to PostgreSQL.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]