[ZEPPELIN-5103]. Simply jdbc interpreter error message

This commit is contained in:
Jeff Zhang 2020-10-23 11:11:06 +08:00
parent 4088295639
commit 4001e1b845
2 changed files with 11 additions and 8 deletions

View file

@ -706,18 +706,17 @@ public class JDBCInterpreter extends KerberosInterpreter {
try {
connection = getConnection(dbPrefix, context);
} catch (Exception e) {
String errorMsg = ExceptionUtils.getStackTrace(e);
LOGGER.error("Fail to getConnection", e);
try {
closeDBPool(user, dbPrefix);
} catch (SQLException e1) {
LOGGER.error("Cannot close DBPool for user, dbPrefix: " + user + dbPrefix, e1);
}
try {
context.out.write(errorMsg);
} catch (IOException ex) {
throw new InterpreterException("Fail to write output", ex);
if (e instanceof SQLException) {
return new InterpreterResult(Code.ERROR, e.getMessage());
} else {
return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
}
return new InterpreterResult(Code.ERROR);
}
if (connection == null) {
return new InterpreterResult(Code.ERROR, "Prefix not found.");
@ -806,7 +805,11 @@ public class JDBCInterpreter extends KerberosInterpreter {
}
} catch (Throwable e) {
LOGGER.error("Cannot run " + sql, e);
return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
if (e instanceof SQLException) {
return new InterpreterResult(Code.ERROR, e.getMessage());
} else {
return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
}
} finally {
//In case user ran an insert/update/upsert statement
if (connection != null) {

View file

@ -298,7 +298,7 @@ public class IPythonInterpreterTest extends BasePythonInterpreterTest {
assertEquals(context.out.toInterpreterResultMessage().get(0).getData(),
InterpreterResult.Code.SUCCESS, result.code());
interpreterResultMessages = context.out.toInterpreterResultMessage();
assertEquals(context.out.toString(), 5, interpreterResultMessages.size());
// the first message is the warning text message.
assertEquals(InterpreterResult.Type.HTML, interpreterResultMessages.get(1).getType());