Uploaded image for project: 'Sqoop (READ-ONLY)'
  1. Sqoop (READ-ONLY)
  2. SQOOP-168

NullPointerException in JdbcWritableBridge.readBytesWritable with nullable binary columns

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0, 1.2.0
    • Fix Version/s: 1.3.0
    • Component/s: import
    • Labels:
      None
    • Environment:
      MS SQL Server 2005/2008. DataDirect sqlserver JDBC driver v4.1.

      Description

      We have some nullable binary(16) columns and I've found that JdbcWritableBridge.readBtyesWritable(...) will throw a NPE when the column value is NULL.

      As in:

      java.lang.NullPointerException
      	at org.apache.hadoop.io.BytesWritable.<init>(BytesWritable.java:54)
      	at com.cloudera.sqoop.lib.JdbcWritableBridge.readBytesWritable(JdbcWritableBridge.java:118)
      	at REPORT.readFields(REPORT.java:341)
      	at com.cloudera.sqoop.mapreduce.db.DBRecordReader.nextKeyValue(DBRecordReader.java:234)
      	at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:448)
      	at org.apache.hadoop.mapreduce.MapContext.nextKeyValue(MapContext.java:67)
      	at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:143)
      	at com.cloudera.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:187)
      	at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:639)
      	at org.apache.hadoop.mapred.MapTask.run(MapTask.java:315)
      	at org.apache.hadoop.mapred.Child$4.run(Child.java:217)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at javax.security.auth.Subject.doAs(Subject.java:396)
      	at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1063)
      	at org.apache.hadoop.mapred.Child.main(Child.java:211)
      

      Here is a suggested fix but I haven't tested it yet (wanted to get the bug logged before I forgot). This seems like the right strategy since the other read* methods will return null for NULL values.

        public static BytesWritable readBytesWritable(int colNum, ResultSet r)
            throws SQLException {
          byte [] bytes = r.getBytes(colNum);
          return bytes == null ? null : new BytesWritable(bytes);
        }
      

      I'm also attaching a patch file in case that makes it any easier to fix.

        Attachments

          Activity

            People

            • Assignee:
              scottf@concur Scott Foster
              Reporter:
              scottf@concur Scott Foster
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: