Copilot commented on code in PR #9305:
URL: https://github.com/apache/seatunnel/pull/9305#discussion_r2084399091


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/JdbcFieldTypeUtils.java:
##########
@@ -56,6 +56,21 @@ public static Double getDouble(ResultSet resultSet, int 
columnIndex) throws SQLE
     }
 
     public static String getString(ResultSet resultSet, int columnIndex) 
throws SQLException {
+        Object obj = resultSet.getObject(columnIndex);
+        if (obj == null) {
+            return null;
+        }
+
+        // Add special handling for the BLOB data type.
+        if (obj instanceof java.sql.Blob) {
+            java.sql.Blob blob = (java.sql.Blob) obj;
+            try {
+                byte[] bytes = blob.getBytes(1, (int) blob.length());
+                return new String(bytes, 
java.nio.charset.StandardCharsets.UTF_8);
+            } finally {
+                blob.free();

Review Comment:
   The getString method unconditionally converts a java.sql.Blob to a UTF-8 
string. Consider integrating a check against the HANDLE_BLOB_AS_STRING 
configuration so that the conversion happens only when explicitly enabled.
   ```suggestion
               if (HANDLE_BLOB_AS_STRING) {
                   java.sql.Blob blob = (java.sql.Blob) obj;
                   try {
                       byte[] bytes = blob.getBytes(1, (int) blob.length());
                       return new String(bytes, 
java.nio.charset.StandardCharsets.UTF_8);
                   } finally {
                       blob.free();
                   }
               } else {
                   throw new SQLException("BLOB handling as string is disabled 
by configuration.");
   ```



##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/config/JdbcConnectionConfig.java:
##########
@@ -64,6 +64,8 @@ public class JdbcConnectionConfig implements Serializable {
 
     private Map<String, String> properties;
 
+    public boolean handleBlobAsString = 
JdbcOptions.HANDLE_BLOB_AS_STRING.defaultValue();
+

Review Comment:
   [nitpick] Consider making the handleBlobAsString field private and providing 
accessor methods to ensure consistency with other configuration fields, 
improving encapsulation.
   ```suggestion
       private boolean handleBlobAsString = 
JdbcOptions.HANDLE_BLOB_AS_STRING.defaultValue();
   
       public boolean isHandleBlobAsString() {
           return handleBlobAsString;
       }
   
       public void setHandleBlobAsString(boolean handleBlobAsString) {
           this.handleBlobAsString = handleBlobAsString;
       }
   ```



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

Reply via email to