You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2022/10/01 13:12:10 UTC

[beam] branch master updated: JdbcIO fetchSize can be set to Integer.MIN_VALUE (#23444)

This is an automated email from the ASF dual-hosted git repository.

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c7a3d40ce1 JdbcIO fetchSize can be set to Integer.MIN_VALUE (#23444)
3c7a3d40ce1 is described below

commit 3c7a3d40ce12eef5f4d361c67f1286b487847f65
Author: Mc <ma...@gmail.com>
AuthorDate: Sat Oct 1 15:12:03 2022 +0200

    JdbcIO fetchSize can be set to Integer.MIN_VALUE (#23444)
    
    * JdbcIO fetchSize can be set to Integer.MIN_VALUE
    
    * Apply suggestions from code review
    
    Add comments about non-standard value.
    
    * Fix formatting and allow users to reset to default value of 0.
    
    * Apply suggestions from code review
    
    Co-authored-by: Lukasz Cwik <lc...@google.com>
---
 .../java/org/apache/beam/sdk/io/jdbc/JdbcIO.java   | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
index a590731e4a0..efb742fb2cb 100644
--- a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
+++ b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
@@ -666,7 +666,13 @@ public class JdbcIO {
      * It should ONLY be used if the default value throws memory errors.
      */
     public ReadRows withFetchSize(int fetchSize) {
-      checkArgument(fetchSize > 0, "fetch size must be > 0");
+      // Note that api.java.sql.Statement#setFetchSize says it only accepts values >= 0
+      // and that MySQL supports using Integer.MIN_VALUE as a hint to stream the ResultSet instead
+      // of loading it into memory. See
+      // https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html for additional details.
+      checkArgument(
+          fetchSize >= 0 || fetchSize == Integer.MIN_VALUE,
+          "fetch size must be >= 0 or equal to Integer.MIN_VALUE");
       return toBuilder().setFetchSize(fetchSize).build();
     }
 
@@ -808,7 +814,13 @@ public class JdbcIO {
      * It should ONLY be used if the default value throws memory errors.
      */
     public Read<T> withFetchSize(int fetchSize) {
-      checkArgument(fetchSize > 0, "fetch size must be > 0");
+      // Note that api.java.sql.Statement#setFetchSize says it only accepts values >= 0
+      // and that MySQL supports using Integer.MIN_VALUE as a hint to stream the ResultSet instead
+      // of loading it into memory. See
+      // https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html for additional details.
+      checkArgument(
+          fetchSize >= 0 || fetchSize == Integer.MIN_VALUE,
+          "fetch size must be >= 0 or equal to Integer.MIN_VALUE");
       return toBuilder().setFetchSize(fetchSize).build();
     }
 
@@ -961,7 +973,13 @@ public class JdbcIO {
      * It should ONLY be used if the default value throws memory errors.
      */
     public ReadAll<ParameterT, OutputT> withFetchSize(int fetchSize) {
-      checkArgument(fetchSize > 0, "fetch size must be >0");
+      // Note that api.java.sql.Statement#setFetchSize says it only accepts values >= 0
+      // and that MySQL supports using Integer.MIN_VALUE as a hint to stream the ResultSet instead
+      // of loading it into memory. See
+      // https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html for additional details.
+      checkArgument(
+          fetchSize >= 0 || fetchSize == Integer.MIN_VALUE,
+          "fetch size must be >= 0 or equal to Integer.MIN_VALUE");
       return toBuilder().setFetchSize(fetchSize).build();
     }