Skip to content

Commit 0a27eee

Browse files
committed
[ZEPPELIN-4771]. Bokeh output in IPythonInterpreter is not in correct format
### What is this PR for? Without this PR, the bokeh output will is not in correct format (see below screenshot). This root cause is the output type is not correct. We should only use html when it is ir kernel for jupyter interpreter. ### What type of PR is it? [Bug Fix ] ### Todos * [ ] - Task ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-4771 ### How should this be tested? * CI pass ### Screenshots (if appropriate) Before ![image](https://user-images.githubusercontent.com/164491/80295130-b76c4800-87a2-11ea-8cb2-f7d213d6b714.png) After ![image](https://user-images.githubusercontent.com/164491/80295171-2cd81880-87a3-11ea-9a80-bffffc4accc0.png) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jeff Zhang <zjffdu@apache.org> Closes #3750 from zjffdu/ZEPPELIN-4771 and squashes the following commits: da6578e [Jeff Zhang] [ZEPPELIN-4771]. Bokeh output in IPythonInterpreter is not in correct format
1 parent 564f166 commit 0a27eee

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class IPythonInterpreter extends JupyterKernelInterpreter {
5757
private String py4jGatewaySecret;
5858

5959
public IPythonInterpreter(Properties properties) {
60-
super(properties);
60+
super("python", properties);
6161
}
6262

6363
@Override

‎rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class IRInterpreter extends JupyterKernelInterpreter {
5454
private SparkRBackend sparkRBackend;
5555

5656
public IRInterpreter(Properties properties) {
57-
super(properties);
57+
super("ir", properties);
5858
}
5959

6060
/**

‎zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelClient.java‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.slf4j.LoggerFactory;
4242

4343
import java.io.IOException;
44-
import java.security.SecureRandom;
4544
import java.util.Iterator;
4645
import java.util.Properties;
4746
import java.util.concurrent.TimeUnit;
@@ -66,24 +65,27 @@ public class JupyterKernelClient {
6665

6766
private Properties properties;
6867
private InterpreterContext context;
69-
private SecureRandom random = new SecureRandom();
68+
private String kernel;
7069

7170
/**
7271
* Construct client for accessing RouteGuide server at {@code host:port}.
7372
*/
74-
public JupyterKernelClient(String host,
75-
int port) {
76-
this(ManagedChannelBuilder.forAddress(host, port).usePlaintext(true), new Properties());
73+
public JupyterKernelClient(String host, int port, String kernel) {
74+
this(ManagedChannelBuilder.forAddress(host, port).usePlaintext(true), new Properties(),
75+
kernel);
7776
}
7877

7978
/**
8079
* Construct client for accessing RouteGuide server using the existing channel.
8180
*/
82-
public JupyterKernelClient(ManagedChannelBuilder<?> channelBuilder, Properties properties) {
81+
public JupyterKernelClient(ManagedChannelBuilder<?> channelBuilder,
82+
Properties properties,
83+
String kernel) {
8384
channel = channelBuilder.build();
8485
blockingStub = JupyterKernelGrpc.newBlockingStub(channel);
8586
asyncStub = JupyterKernelGrpc.newStub(channel);
8687
this.properties = properties;
88+
this.kernel = kernel;
8789
}
8890

8991
public void shutdown() throws InterruptedException {
@@ -170,7 +172,8 @@ public void onNext(ExecuteResponse executeResponse) {
170172
}
171173
// explicitly use html output for ir kernel in some cases. otherwise some
172174
// R packages doesn't work. e.g. googlevis
173-
if (executeResponse.getOutput().contains("<script type=\"text/javascript\">")) {
175+
if (kernel.equals("ir") && executeResponse.getOutput()
176+
.contains("<script type=\"text/javascript\">")) {
174177
interpreterOutput.write("\n%html ".getBytes());
175178
}
176179
interpreterOutput.write(executeResponse.getOutput().getBytes());
@@ -306,7 +309,7 @@ public boolean isMaybeKernelFailed() {
306309
}
307310

308311
public static void main(String[] args) {
309-
JupyterKernelClient client = new JupyterKernelClient("localhost", 50053);
312+
JupyterKernelClient client = new JupyterKernelClient("localhost", 50053, "python");
310313
client.status(StatusRequest.newBuilder().build());
311314

312315
ExecuteResponse response = client.block_execute(ExecuteRequest.newBuilder().

‎zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelInterpreter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void open() throws InterpreterException {
125125

126126
jupyterKernelClient = new JupyterKernelClient(ManagedChannelBuilder.forAddress("127.0.0.1",
127127
kernelPort).usePlaintext(true).maxInboundMessageSize(message_size),
128-
getProperties());
128+
getProperties(), kernel);
129129
launchJupyterKernel(kernelPort);
130130
} catch (Exception e) {
131131
throw new InterpreterException("Fail to open JupyterKernelInterpreter:\n" +

0 commit comments

Comments
 (0)