mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
ZEPPELIN-349: Resolve NPE on null cell values
This commit is contained in:
parent
a884e0278f
commit
fff3448ab4
2 changed files with 25 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,27 @@ public class PostgreSqlInterpreterTest extends BasicJDBCTestCaseAdapter {
|
|||
.getJdbcConnection().isClosed());
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue