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/02/21 05:04:56 UTC

zeppelin git commit: ZEPPELIN-3239. unicode characters in an iPython paragraph makes Spark interpreter irresponsive

Repository: zeppelin
Updated Branches:
  refs/heads/master d220c0118 -> a791fad59


ZEPPELIN-3239. unicode characters in an iPython paragraph makes Spark interpreter irresponsive

### What is this PR for?

Fix the unicode issues in python2.

### What type of PR is it?
[Bug Fix | Improvement ]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-3239

### How should this be tested?
* Unit test is added

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jeff Zhang <zj...@apache.org>

Closes #2810 from zjffdu/ZEPPELIN-3239 and squashes the following commits:

70c8b4c [Jeff Zhang] ZEPPELIN-3239. unicode characters in an iPython paragraph makes Spark interpreter irrsponsive


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/a791fad5
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/a791fad5
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/a791fad5

Branch: refs/heads/master
Commit: a791fad5970905edd07bdb8afcc00497fb3540f5
Parents: d220c01
Author: Jeff Zhang <zj...@apache.org>
Authored: Tue Feb 20 16:58:47 2018 +0800
Committer: Jeff Zhang <zj...@apache.org>
Committed: Wed Feb 21 13:04:50 2018 +0800

----------------------------------------------------------------------
 .../resources/grpc/python/ipython_server.py     |  3 +--
 .../zeppelin/python/IPythonInterpreterTest.java | 21 +++++++++++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a791fad5/python/src/main/resources/grpc/python/ipython_server.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/grpc/python/ipython_server.py b/python/src/main/resources/grpc/python/ipython_server.py
index 98fa616..4b68efd 100644
--- a/python/src/main/resources/grpc/python/ipython_server.py
+++ b/python/src/main/resources/grpc/python/ipython_server.py
@@ -27,7 +27,6 @@ import ipython_pb2_grpc
 
 _ONE_DAY_IN_SECONDS = 60 * 60 * 24
 
-
 is_py2 = sys.version[0] == '2'
 if is_py2:
     import Queue as queue
@@ -51,7 +50,7 @@ class IPython(ipython_pb2_grpc.IPythonServicer):
 
     def execute(self, request, context):
         print("execute code:\n")
-        print(request.code)
+        print(request.code.encode('utf-8'))
         sys.stdout.flush()
         stdout_queue = queue.Queue(maxsize = 10)
         stderr_queue = queue.Queue(maxsize = 10)

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a791fad5/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
----------------------------------------------------------------------
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 cb854d6..ec59482 100644
--- a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
@@ -81,18 +81,33 @@ public class IPythonInterpreterTest {
     InterpreterResult result = interpreter.interpret("from __future__ import print_function", getInterpreterContext());
     assertEquals(InterpreterResult.Code.SUCCESS, result.code());
 
-    result = interpreter.interpret("import sys\nprint(sys.version_info)", getInterpreterContext());
+
+    InterpreterContext context = getInterpreterContext();
+    result = interpreter.interpret("import sys\nprint(sys.version[0])", context);
     assertEquals(InterpreterResult.Code.SUCCESS, result.code());
+    Thread.sleep(100);
+    List<InterpreterResultMessage> interpreterResultMessages = context.out.getInterpreterResultMessages();
+    assertEquals(1, interpreterResultMessages.size());
+    boolean isPython2 = interpreterResultMessages.get(0).getData().equals("2\n");
 
     // single output without print
-    InterpreterContext context = getInterpreterContext();
+    context = getInterpreterContext();
     result = interpreter.interpret("'hello world'", context);
     Thread.sleep(100);
     assertEquals(InterpreterResult.Code.SUCCESS, result.code());
-    List<InterpreterResultMessage> interpreterResultMessages = context.out.getInterpreterResultMessages();
+    interpreterResultMessages = context.out.getInterpreterResultMessages();
     assertEquals(1, interpreterResultMessages.size());
     assertEquals("'hello world'", interpreterResultMessages.get(0).getData());
 
+    // unicode
+    context = getInterpreterContext();
+    result = interpreter.interpret("print(u'你好')", context);
+    Thread.sleep(100);
+    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
+    interpreterResultMessages = context.out.getInterpreterResultMessages();
+    assertEquals(1, interpreterResultMessages.size());
+    assertEquals("你好\n", interpreterResultMessages.get(0).getData());
+    
     // only the last statement is printed
     context = getInterpreterContext();
     result = interpreter.interpret("'hello world'\n'hello world2'", context);