Details
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.