Repository: nifi
Updated Branches:
  refs/heads/master 6b5950647 -> 46b81058c


NIFI-2602: Fixed NPE in SelectHiveQL when CSV output and null column value

This closes #898.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/46b81058
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/46b81058
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/46b81058

Branch: refs/heads/master
Commit: 46b81058c7fa0914bf5df34d82430bb77bffa6c5
Parents: 6b59506
Author: Matt Burgess <[email protected]>
Authored: Thu Aug 18 19:18:39 2016 -0400
Committer: Pierre Villard <[email protected]>
Committed: Fri Aug 19 09:56:26 2016 +0200

----------------------------------------------------------------------
 .../org/apache/nifi/util/hive/HiveJdbcCommon.java    | 13 +++++++++++--
 .../nifi/processors/hive/TestSelectHiveQL.java       | 15 ++++++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/46b81058/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
index 5de36dc..fb4ac84 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
@@ -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:
-                        rowValues.add(value.toString());
+                        if (value != null) {
+                            rowValues.add(value.toString());
+                        } else {
+                            rowValues.add("");
+                        }
                 }
             }
             // Write row values

http://git-wip-us.apache.org/repos/asf/nifi/blob/46b81058/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java
index 5386030..8142e3f 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java
@@ -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(",");
-                assertEquals(3, values.length);
-                // Assert the name has been quoted
-                assertTrue(values[1].startsWith("\""));
-                assertTrue(values[1].endsWith("\""));
+                if(recordsFromStream < (nrOfRows - 10)) {
+                    assertEquals(3, values.length);
+                    assertTrue(values[1].startsWith("\""));
+                    assertTrue(values[1].endsWith("\""));
+                } else {
+                    assertEquals(2, values.length); // Middle value is null
+                }
             }
         }
         assertEquals(nrOfRows - 10, recordsFromStream);

Reply via email to