Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1941#discussion_r62833230
  
    --- Diff: 
flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormat.java
 ---
    @@ -95,32 +95,32 @@ private void establishConnection() throws SQLException, 
ClassNotFoundException {
                }
        }
     
    -   private enum SupportedTypes {
    -           BOOLEAN,
    -           BYTE,
    -           SHORT,
    -           INTEGER,
    -           LONG,
    -           STRING,
    -           FLOAT,
    -           DOUBLE
    -   }
    -
        /**
         * Adds a record to the prepared statement.
         * <p>
         * When this method is called, the output format is guaranteed to be 
opened.
    +    * 
    +    * WARNING: this may fail if the JDBC driver doesn't handle null 
correctly and no column types specified in the SqlRow
         *
         * @param tuple The records to add to the output.
         * @throws IOException Thrown, if the records could not be added due to 
an I/O problem.
         */
        @Override
    -   public void writeRecord(OUT tuple) throws IOException {
    +   public void writeRecord(Row tuple) throws IOException {
                try {
    -                   if (types == null) {
    -                           extractTypes(tuple);
    +                   for (int index = 0; index < tuple.productArity(); 
index++) {
    +                           if (tuple.productElement(index) == null && 
typesArray != null && typesArray.length > 0) {
    +                                   if (typesArray.length == 
tuple.productArity()) {
    +                                           upload.setNull(index + 1, 
typesArray[index]);
    +                                   } else {
    +                                           LOG.warn("Column SQL types 
array doesn't match arity of SqlRow! Check the passed array...");
    +                                   }
    +                           } else {
    +                                   //try generic set if no column type 
available
    +                                   //WARNING: this may fail if the JDBC 
driver doesn't handle null correctly
    +                                   upload.setObject(index + 1, 
tuple.productElement(index));
    --- End diff --
    
    Are there any drawbacks of using the generic `setObject()` method compared 
to the typed methods? If yes, we should use them if the types are specified.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to