NIFI-6039: Avoid NPE if Record Writer does not provide schema

This closes #3310.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Mark Payne 2019-02-14 16:04:25 -05:00 committed by Bryan Bende
parent b508d6bfbc
commit 319979f256
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
1 changed files with 14 additions and 8 deletions

View File

@ -197,17 +197,20 @@ public class ResultSetRecordSet implements RecordSet, Closeable {
} }
final String columnName = rs.getMetaData().getColumnName(columnIndex); final String columnName = rs.getMetaData().getColumnName(columnIndex);
if (readerSchema != null) {
Optional<DataType> dataType = readerSchema.getDataType(columnName); Optional<DataType> dataType = readerSchema.getDataType(columnName);
if (dataType.isPresent()) { if (dataType.isPresent()) {
return dataType.get(); return dataType.get();
} }
}
final Object obj = rs.getObject(columnIndex); final Object obj = rs.getObject(columnIndex);
if (obj == null || !(obj instanceof Record)) { if (!(obj instanceof Record)) {
final List<DataType> dataTypes = Stream.of(RecordFieldType.BIGINT, RecordFieldType.BOOLEAN, RecordFieldType.BYTE, RecordFieldType.CHAR, RecordFieldType.DATE, final List<DataType> dataTypes = Stream.of(RecordFieldType.BIGINT, RecordFieldType.BOOLEAN, RecordFieldType.BYTE, RecordFieldType.CHAR, RecordFieldType.DATE,
RecordFieldType.DOUBLE, RecordFieldType.FLOAT, RecordFieldType.INT, RecordFieldType.LONG, RecordFieldType.SHORT, RecordFieldType.STRING, RecordFieldType.TIME, RecordFieldType.DOUBLE, RecordFieldType.FLOAT, RecordFieldType.INT, RecordFieldType.LONG, RecordFieldType.SHORT, RecordFieldType.STRING, RecordFieldType.TIME,
RecordFieldType.TIMESTAMP) RecordFieldType.TIMESTAMP)
.map(recordFieldType -> recordFieldType.getDataType()) .map(RecordFieldType::getDataType)
.collect(Collectors.toList()); .collect(Collectors.toList());
return RecordFieldType.CHOICE.getChoiceDataType(dataTypes); return RecordFieldType.CHOICE.getChoiceDataType(dataTypes);
@ -219,10 +222,13 @@ public class ResultSetRecordSet implements RecordSet, Closeable {
} }
default: { default: {
final String columnName = rs.getMetaData().getColumnName(columnIndex); final String columnName = rs.getMetaData().getColumnName(columnIndex);
if (readerSchema != null) {
Optional<DataType> dataType = readerSchema.getDataType(columnName); Optional<DataType> dataType = readerSchema.getDataType(columnName);
if (dataType.isPresent()) { if (dataType.isPresent()) {
return dataType.get(); return dataType.get();
} }
}
return getFieldType(sqlType, rs.getMetaData().getColumnClassName(columnIndex)).getDataType(); return getFieldType(sqlType, rs.getMetaData().getColumnClassName(columnIndex)).getDataType();
} }