This is an automated email from the ASF dual-hosted git repository. zjffdu pushed a commit to branch branch-0.9 in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/branch-0.9 by this push: new ec88043 [ZEPPELIN-5103]. Simply jdbc interpreter error message ec88043 is described below commit ec8804325c4a3bc6fc7a231f22eef8f0578853a3 Author: Jeff Zhang <zjf...@apache.org> AuthorDate: Fri Oct 23 11:11:06 2020 +0800 [ZEPPELIN-5103]. Simply jdbc interpreter error message ### What is this PR for? In this PR, I would only print exception message when it is SQLException, otherwise would print the full stacktrace, because in this case it is most likely due to jdbc interpreter's internal error. ### What type of PR is it? [Improvement] ### Todos * [ ] - Task ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-5103 ### How should this be tested? * CI pass ### Screenshots (if appropriate)  ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jeff Zhang <zjf...@apache.org> Closes #3952 from zjffdu/ZEPPELIN-5103 and squashes the following commits: 4001e1b84 [Jeff Zhang] [ZEPPELIN-5103]. Simply jdbc interpreter error message (cherry picked from commit 6981c4dd74c222f87c38fe4a266b3f84768a5049) Signed-off-by: Jeff Zhang <zjf...@apache.org> --- .../java/org/apache/zeppelin/jdbc/JDBCInterpreter.java | 17 ++++++++++------- .../apache/zeppelin/python/IPythonInterpreterTest.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java index 76d4d20..f54f5b5 100644 --- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java +++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java @@ -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) { diff --git a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java index c2d8ae3..08e0c8d 100644 --- a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java +++ b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java @@ -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());