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 NCHAR:
|
||||||
case NVARCHAR:
|
case NVARCHAR:
|
||||||
case VARCHAR:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
rowValues.add(value.toString());
|
if (value != null) {
|
||||||
|
rowValues.add(value.toString());
|
||||||
|
} else {
|
||||||
|
rowValues.add("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Write row values
|
// Write row values
|
||||||
|
|
|
@ -205,9 +205,11 @@ public class TestSelectHiveQL {
|
||||||
Random rng = new Random(53496);
|
Random rng = new Random(53496);
|
||||||
final int nrOfRows = 100;
|
final int nrOfRows = 100;
|
||||||
stmt.executeUpdate("insert into persons values (1, 'Joe Smith', " + rng.nextInt(469947) + ")");
|
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 (" + i + ", 'Someone Else', " + rng.nextInt(469947) + ")");
|
||||||
}
|
}
|
||||||
|
stmt.executeUpdate("insert into persons values (" + nrOfRows + ", 'Last Person', NULL)");
|
||||||
|
|
||||||
LOGGER.info("test data loaded");
|
LOGGER.info("test data loaded");
|
||||||
|
|
||||||
runner.setProperty(SelectHiveQL.HIVEQL_SELECT_QUERY, query);
|
runner.setProperty(SelectHiveQL.HIVEQL_SELECT_QUERY, query);
|
||||||
|
@ -254,10 +256,13 @@ public class TestSelectHiveQL {
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
recordsFromStream++;
|
recordsFromStream++;
|
||||||
String[] values = line.split(",");
|
String[] values = line.split(",");
|
||||||
assertEquals(3, values.length);
|
if(recordsFromStream < (nrOfRows - 10)) {
|
||||||
// Assert the name has been quoted
|
assertEquals(3, values.length);
|
||||||
assertTrue(values[1].startsWith("\""));
|
assertTrue(values[1].startsWith("\""));
|
||||||
assertTrue(values[1].endsWith("\""));
|
assertTrue(values[1].endsWith("\""));
|
||||||
|
} else {
|
||||||
|
assertEquals(2, values.length); // Middle value is null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(nrOfRows - 10, recordsFromStream);
|
assertEquals(nrOfRows - 10, recordsFromStream);
|
||||||
|
|
Loading…
Reference in New Issue