Repository: zeppelin Updated Branches: refs/heads/master b1e06919f -> 93e6e0bfc
[Pyspark] checking nhooks count. ### What is this PR for? if the `nhooks` value is `0` in this(https://github.com/apache/zeppelin/blob/master/spark/src/main/resources/python/zeppelin_pyspark.py#L324) line, python code will run twice. ### What type of PR is it? Bug Fix | Improvement ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-2024 ### How should this be tested? - comment https://github.com/apache/zeppelin/blob/master/spark/src/main/java/org/apache/zeppelin/spark/PySparkInterpreter.java#L114 line and build. - run pyspark code(eg, `print("hi")`), then you can see it run twice. ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: astroshim <hss...@zepl.com> Closes #1924 from astroshim/fix/pythoncode and squashes the following commits: fdde8a6 [astroshim] fix testcase 1c50c6d [astroshim] add checking nhooks count Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/93e6e0bf Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/93e6e0bf Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/93e6e0bf Branch: refs/heads/master Commit: 93e6e0bfccac061135d3fd0dd3a1a198dcf89dcb Parents: b1e0691 Author: astroshim <hss...@zepl.com> Authored: Sun Jan 22 00:20:54 2017 -0800 Committer: Lee moon soo <m...@apache.org> Committed: Sat Jan 28 05:42:11 2017 +0900 ---------------------------------------------------------------------- spark/src/main/resources/python/zeppelin_pyspark.py | 4 +++- .../apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/93e6e0bf/spark/src/main/resources/python/zeppelin_pyspark.py ---------------------------------------------------------------------- diff --git a/spark/src/main/resources/python/zeppelin_pyspark.py b/spark/src/main/resources/python/zeppelin_pyspark.py index dbc7305..c59d2f4 100644 --- a/spark/src/main/resources/python/zeppelin_pyspark.py +++ b/spark/src/main/resources/python/zeppelin_pyspark.py @@ -321,7 +321,9 @@ while True : # so that the last statement's evaluation will be printed to stdout sc.setJobGroup(jobGroup, "Zeppelin") code = compile('\n'.join(final_code), '<stdin>', 'exec', ast.PyCF_ONLY_AST, 1) - to_run_hooks = code.body[-nhooks:] + to_run_hooks = [] + if (nhooks > 0): + to_run_hooks = code.body[-nhooks:] to_run_exec, to_run_single = (code.body[:-(nhooks + 1)], [code.body[-(nhooks + 1)]]) http://git-wip-us.apache.org/repos/asf/zeppelin/blob/93e6e0bf/spark/src/test/java/org/apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java ---------------------------------------------------------------------- diff --git a/spark/src/test/java/org/apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java b/spark/src/test/java/org/apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java index 9a2a88a..17b2128 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/PySparkInterpreterMatplotlibTest.java @@ -213,7 +213,7 @@ public class PySparkInterpreterMatplotlibTest { // again but in a different color. ret = pyspark.interpret("plt.plot([1, 2, 3])", context); ret2 = pyspark.interpret("plt.show()", context); - assertNotSame(ret1.message().get(1).getData(), ret2.message().get(1).getData()); + assertNotSame(ret1.message().get(0).getData(), ret2.message().get(0).getData()); } @Test @@ -226,7 +226,7 @@ public class PySparkInterpreterMatplotlibTest { ret = pyspark.interpret("plt.plot([1, 2, 3])", context); ret = pyspark.interpret("plt.show()", context); assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code()); - assertEquals(ret.message().toString(), Type.ANGULAR, ret.message().get(1).getType()); + assertEquals(ret.message().toString(), Type.ANGULAR, ret.message().get(0).getType()); // Check if the figure data is in the Angular Object Registry AngularObjectRegistry registry = context.getAngularObjectRegistry();