You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2015/10/19 07:22:12 UTC
incubator-zeppelin git commit: ZEPPELIN-349: Resolve NPE on null cell
values
Repository: incubator-zeppelin
Updated Branches:
refs/heads/master ecc497011 -> baab124cf
ZEPPELIN-349: Resolve NPE on null cell values
When the query response contains null column values the following NPE is thrown:
java.lang.NullPointerException
at org.apache.zeppelin.postgresql.PostgreSqlInterpreter.replaceReservedChars(PostgreSqlInterpreter.java:278)
at org.apache.zeppelin.postgresql.PostgreSqlInterpreter.executeSql(PostgreSqlInterpreter.java:235)
Author: tzolov <ch...@gmail.com>
Closes #348 from tzolov/ZEPPELIN-349 and squashes the following commits:
de70c88 [tzolov] ZEPPELIN-349: Format test code
fff3448 [tzolov] ZEPPELIN-349: Resolve NPE on null cell values
Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/baab124c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/baab124c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/baab124c
Branch: refs/heads/master
Commit: baab124cf310545cbc6cf0b4e29b4f20b54d4f48
Parents: ecc4970
Author: tzolov <ch...@gmail.com>
Authored: Fri Oct 16 23:47:45 2015 +0200
Committer: Lee moon soo <mo...@apache.org>
Committed: Mon Oct 19 14:23:07 2015 +0900
----------------------------------------------------------------------
.../postgresql/PostgreSqlInterpreter.java | 4 ++++
.../postgresql/PostgreSqlInterpreterTest.java | 21 ++++++++++++++++++++
2 files changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/baab124c/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java
----------------------------------------------------------------------
diff --git a/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java b/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java
index 57336c4..4189a74 100644
--- a/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java
+++ b/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java
@@ -89,6 +89,7 @@ public class PostgreSqlInterpreter extends Interpreter {
static final String POSTGRESQL_SERVER_PASSWORD = "postgresql.password";
static final String POSTGRESQL_SERVER_DRIVER_NAME = "postgresql.driver.name";
static final String POSTGRESQL_SERVER_MAX_RESULT = "postgresql.max.result";
+ static final String EMPTY_COLUMN_VALUE = "";
static {
Interpreter.register(
@@ -275,6 +276,9 @@ public class PostgreSqlInterpreter extends Interpreter {
* For %table response replace Tab and Newline characters from the content.
*/
private String replaceReservedChars(boolean isTableResponseType, String str) {
+ if (str == null) {
+ return EMPTY_COLUMN_VALUE;
+ }
return (!isTableResponseType) ? str : str.replace(TAB, WhITESPACE).replace(NEWLINE, WhITESPACE);
}
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/baab124c/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java
----------------------------------------------------------------------
diff --git a/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java b/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java
index d59c071..9c8eae1 100644
--- a/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java
+++ b/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java
@@ -127,6 +127,27 @@ public class PostgreSqlInterpreterTest extends BasicJDBCTestCaseAdapter {
}
@Test
+ public void testNullColumnResult() throws SQLException {
+
+ when(psqlInterpreter.getMaxResult()).thenReturn(1000);
+
+ String sqlQuery = "select * from t";
+
+ result.addColumn("col1", new String[] {"val11", null});
+ result.addColumn("col2", new String[] {null, "val22"});
+
+ InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null);
+
+ assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
+ assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type());
+ assertEquals("col1\tcol2\nval11\t\n\tval22\n", interpreterResult.message());
+
+ verifySQLStatementExecuted(sqlQuery);
+ verifyAllResultSetsClosed();
+ verifyAllStatementsClosed();
+ }
+
+ @Test
public void testSelectQuery() throws SQLException {
when(psqlInterpreter.getMaxResult()).thenReturn(1000);