mirror of https://github.com/apache/nifi.git
NIFI-2602: Fixed NPE in SelectHiveQL when CSV output and null column value
This closes #898.
This commit is contained in:
parent
6b5950647a
commit
46b81058c7
|
@ -320,10 +320,19 @@ public class HiveJdbcCommon {
|
|||
case NCHAR:
|
||||
case NVARCHAR:
|
||||
case VARCHAR:
|
||||
rowValues.add("\"" + StringEscapeUtils.escapeCsv(rs.getString(i)) + "\"");
|
||||
String valueString = rs.getString(i);
|
||||
if (valueString != null) {
|
||||
rowValues.add("\"" + StringEscapeUtils.escapeCsv(valueString) + "\"");
|
||||
} else {
|
||||
rowValues.add("");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (value != null) {
|
||||
rowValues.add(value.toString());
|
||||
} else {
|
||||
rowValues.add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Write row values
|
||||
|
|
|
@ -205,9 +205,11 @@ public class TestSelectHiveQL {
|
|||
Random rng = new Random(53496);
|
||||
final int nrOfRows = 100;
|
||||
stmt.executeUpdate("insert into persons values (1, 'Joe Smith', " + rng.nextInt(469947) + ")");
|
||||
for (int i = 2; i <= nrOfRows; i++) {
|
||||
for (int i = 2; i < nrOfRows; i++) {
|
||||
stmt.executeUpdate("insert into persons values (" + i + ", 'Someone Else', " + rng.nextInt(469947) + ")");
|
||||
}
|
||||
stmt.executeUpdate("insert into persons values (" + nrOfRows + ", 'Last Person', NULL)");
|
||||
|
||||
LOGGER.info("test data loaded");
|
||||
|
||||
runner.setProperty(SelectHiveQL.HIVEQL_SELECT_QUERY, query);
|
||||
|
@ -254,10 +256,13 @@ public class TestSelectHiveQL {
|
|||
while ((line = br.readLine()) != null) {
|
||||
recordsFromStream++;
|
||||
String[] values = line.split(",");
|
||||
if(recordsFromStream < (nrOfRows - 10)) {
|
||||
assertEquals(3, values.length);
|
||||
// Assert the name has been quoted
|
||||
assertTrue(values[1].startsWith("\""));
|
||||
assertTrue(values[1].endsWith("\""));
|
||||
} else {
|
||||
assertEquals(2, values.length); // Middle value is null
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(nrOfRows - 10, recordsFromStream);
|
||||
|
|
Loading…
Reference in New Issue