Repository: incubator-zeppelin Updated Branches: refs/heads/master 64acfa9c8 -> e5f4aeade
[ZEPPELIN-679] only print the error message for SQL exceptions ### What is this PR for? Most of the SQL exceptions are syntax errors. Printing the full stack trace is not necessary. We should only print the error message to avoid distracting the users ### What type of PR is it? Improvement ### Todos ### What is the Jira issue? [ZEPPELIN-679](https://issues.apache.org/jira/browse/ZEPPELIN-679) ### How should this be tested? ### 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: Zhong Wang <[email protected]> Closes #754 from zhongneu/less-sql-err-msg and squashes the following commits: ebb6b99 [Zhong Wang] add configuration for stacktrace 1ba8bb3 [Zhong Wang] fix test ca338ef [Zhong Wang] log full stack trace in interpreter log 25014ec [Zhong Wang] clearer exception handling logic 39dd274 [Zhong Wang] only print the error message for SQL exceptions Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/e5f4aead Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/e5f4aead Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/e5f4aead Branch: refs/heads/master Commit: e5f4aeade27874d0e45e1dc54530f00c7c0c4b42 Parents: 64acfa9 Author: Zhong Wang <[email protected]> Authored: Thu Mar 3 20:42:10 2016 -0800 Committer: Lee moon soo <[email protected]> Committed: Wed Mar 9 09:25:03 2016 -0800 ---------------------------------------------------------------------- .../apache/zeppelin/spark/SparkSqlInterpreter.java | 14 +++++++++++++- .../zeppelin/spark/SparkSqlInterpreterTest.java | 11 ++++------- 2 files changed, 17 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/e5f4aead/spark/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java ---------------------------------------------------------------------- diff --git a/spark/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java b/spark/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java index 0be7c2d..3b850b4 100644 --- a/spark/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java +++ b/spark/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java @@ -60,6 +60,10 @@ public class SparkSqlInterpreter extends Interpreter { SparkInterpreter.getSystemDefault("ZEPPELIN_SPARK_CONCURRENTSQL", "zeppelin.spark.concurrentSQL", "false"), "Execute multiple SQL concurrently if set true.") + .add("zeppelin.spark.sql.stacktrace", + SparkInterpreter.getSystemDefault("ZEPPELIN_SPARK_SQL_STACKTRACE", + "zeppelin.spark.sql.stacktrace", "false"), + "Show full exception stacktrace for SQL queries if set to true.") .build()); } @@ -131,8 +135,16 @@ public class SparkSqlInterpreter extends Interpreter { // Therefore need to use reflection to keep binary compatibility for all spark versions. Method sqlMethod = sqlc.getClass().getMethod("sql", String.class); rdd = sqlMethod.invoke(sqlc, st); + } catch (InvocationTargetException ite) { + if (Boolean.parseBoolean(getProperty("zeppelin.spark.sql.stacktrace"))) { + throw new InterpreterException(ite); + } + logger.error("Invocation target exception", ite); + String msg = ite.getTargetException().getMessage() + + "\nset zeppelin.spark.sql.stacktrace = true to see full stacktrace"; + return new InterpreterResult(Code.ERROR, msg); } catch (NoSuchMethodException | SecurityException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { + | IllegalArgumentException e) { throw new InterpreterException(e); } http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/e5f4aead/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java ---------------------------------------------------------------------- diff --git a/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java index e5ea9a0..c2cc1e6 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java @@ -110,13 +110,10 @@ public class SparkSqlInterpreterTest { assertEquals(Type.TABLE, ret.type()); assertEquals("name\tage\nmoon\t33\npark\t34\n", ret.message()); - try { - sql.interpret("select wrong syntax", context); - fail("Exception not catched"); - } catch (Exception e) { - // okay - LOGGER.info("Exception in SparkSqlInterpreterTest while test ", e); - } + ret = sql.interpret("select wrong syntax", context); + assertEquals(InterpreterResult.Code.ERROR, ret.code()); + assertTrue(ret.message().length() > 0); + assertEquals(InterpreterResult.Code.SUCCESS, sql.interpret("select case when name==\"aa\" then name else name end from test", context).code()); }
