koyr-exem commented on code in PR #909:
URL: 
https://github.com/apache/hugegraph-toolchain/pull/909#discussion_r4608129510


##########
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:
   Thanks — the test's Connection proxy returned null for getAutoCommit. It now 
answers getAutoCommit/setAutoCommit, and the test asserts the call order 
setAutoCommit(false) → setFetchSize(batch_size) → executeQuery. Fixed in 
38b7c105.



##########
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:
   Good point. I scoped the title and description to PostgreSQL. For MySQL, 
users can add useCursorFetch=true to the URL; making MySQL stream by default 
(Integer.MIN_VALUE) changes connection behavior, so I'd rather leave that to a 
separate issue.



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

Reply via email to