You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2018/08/14 02:59:48 UTC
zeppelin git commit: [ZEPPELIN-3687] Fix IndexError in python
interpreter with empty input
Repository: zeppelin
Updated Branches:
refs/heads/master 6beb1bb3c -> cd16547cb
[ZEPPELIN-3687] Fix IndexError in python interpreter with empty input
### What is this PR for?
If input of python or pyspark interpreter is empty (contains only comments), it will fail with `IndexError` from `zeppelin_python.py`.
### What type of PR is it?
Bug Fix
### What is the Jira issue?
[ZEPPELIN-3687](https://issues.apache.org/jira/projects/ZEPPELIN/issues/ZEPPELIN-3687)
### Screenshots
## Before:
![screen-shot-2018-08-05-at-23 29 34](https://user-images.githubusercontent.com/16215034/43775282-d1274caa-9a54-11e8-9c6c-3b882f96cf7e.jpg)
![screen-shot-2018-08-07-at-11 48 10](https://user-images.githubusercontent.com/16215034/43775285-d385ad2a-9a54-11e8-9a14-aa0080cc5824.jpg)
## After:
![screen-shot-2018-08-07-at-15 11 452](https://user-images.githubusercontent.com/16215034/43775306-e17acf28-9a54-11e8-8378-9b6a8b1c817c.jpg)
![screen-shot-2018-08-07-at-15 11 45](https://user-images.githubusercontent.com/16215034/43775313-e51f81c8-9a54-11e8-829f-d2aba1cc9613.jpg)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: oxygen311 <al...@mail.ru>
Author: Alexey <al...@mail.ru>
Closes #3115 from oxygen311/DW-17854 and squashes the following commits:
54004b098 [oxygen311] Fix tests
ad8d07f5e [Alexey] Add test for empty input
5d0fdd296 [oxygen311] Fix IndexError in python interpreter
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/cd16547c
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/cd16547c
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/cd16547c
Branch: refs/heads/master
Commit: cd16547cbfa784c4b3a307f59aceebd120851861
Parents: 6beb1bb
Author: oxygen311 <al...@mail.ru>
Authored: Wed Aug 8 12:35:54 2018 +0200
Committer: Jeff Zhang <zj...@apache.org>
Committed: Tue Aug 14 10:59:43 2018 +0800
----------------------------------------------------------------------
python/src/main/resources/python/zeppelin_python.py | 2 +-
.../zeppelin/python/BasePythonInterpreterTest.java | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/cd16547c/python/src/main/resources/python/zeppelin_python.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/python/zeppelin_python.py b/python/src/main/resources/python/zeppelin_python.py
index e99de5e..db224e4 100644
--- a/python/src/main/resources/python/zeppelin_python.py
+++ b/python/src/main/resources/python/zeppelin_python.py
@@ -145,7 +145,7 @@ while True :
if (nhooks > 0):
to_run_hooks = code.body[-nhooks:]
to_run_exec, to_run_single = (code.body[:-(nhooks + 1)],
- [code.body[-(nhooks + 1)]])
+ [code.body[-(nhooks + 1)]] if len(code.body) > nhooks else [])
try:
for node in to_run_exec:
mod = ast.Module([node])
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/cd16547c/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java
----------------------------------------------------------------------
diff --git a/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java
index 25cb253..a51c053 100644
--- a/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java
@@ -185,6 +185,22 @@ public abstract class BasePythonInterpreterTest {
interpreterResultMessages = context.out.toInterpreterResultMessage();
assertEquals(1, interpreterResultMessages.size());
assertEquals("there is no Error: ok\n", interpreterResultMessages.get(0).getData());
+
+ // ZEPPELIN-3687
+ context = getInterpreterContext();
+ result = interpreter.interpret("# print('Hello')", context);
+ Thread.sleep(100);
+ assertEquals(InterpreterResult.Code.SUCCESS, result.code());
+ interpreterResultMessages = context.out.toInterpreterResultMessage();
+ assertEquals(0, interpreterResultMessages.size());
+
+ context = getInterpreterContext();
+ result = interpreter.interpret(
+ "# print('Hello')\n# print('How are u?')\n# time.sleep(1)", context);
+ Thread.sleep(100);
+ assertEquals(InterpreterResult.Code.SUCCESS, result.code());
+ interpreterResultMessages = context.out.toInterpreterResultMessage();
+ assertEquals(0, interpreterResultMessages.size());
}
@Test