You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/09/23 23:25:43 UTC

[GitHub] [beam] pabloem commented on a change in pull request #15566: [BEAM-12925] Correct behavior retrieving NULL values from JDBC.

pabloem commented on a change in pull request #15566:
URL: https://github.com/apache/beam/pull/15566#discussion_r715219964



##########
File path: sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/SchemaUtil.java
##########
@@ -351,7 +351,12 @@ private BeamRowMapper(Schema schema, List<ResultSetFieldExtractor> fieldExtracto
     public Row mapRow(ResultSet rs) throws Exception {
       Row.Builder rowBuilder = Row.withSchema(schema);
       for (int i = 0; i < schema.getFieldCount(); i++) {
-        rowBuilder.addValue(fieldExtractors.get(i).extract(rs, i + 1));
+        Object value = fieldExtractors.get(i).extract(rs, i + 1);
+        if (rs.wasNull() && schema.getField(i).getType().getNullable()) {
+          rowBuilder.addValue(null);
+        } else {
+          rowBuilder.addValue(value);

Review comment:
       if the value was null and the field is not nullable, we would be setting the wrong value, right? (e.g. [for numeric columns, it would be 0](https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#getShort(int))) - should we be erroring out? perhaps we should:
   
   ```
           if (rs.wasNull()) {
             rowBuilder.addValue(null);
           } else {
             rowBuilder.addValue(value);
           }
   ```
   
   what are your thoughts?
   
   fyi @reuvenlax 




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org