This is an automated email from the ASF dual-hosted git repository. zjffdu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new e9cae61 [ZEPPELIN-4509]. Make JupyterKernelInterpreter extends AbstractInterpreter e9cae61 is described below commit e9cae61360bbbf47637c06a95f8dd8ee77920af8 Author: Jeff Zhang <zjf...@apache.org> AuthorDate: Thu Dec 26 12:06:16 2019 +0800 [ZEPPELIN-4509]. Make JupyterKernelInterpreter extends AbstractInterpreter ### What is this PR for? This is a straightforward PR which just make `JupyterKernelInterpreter` extends `AbstractInterpreter` so that we can leverage the features in `JupyterKernelInterpreter` such as variable interpolation. ### What type of PR is it? [ Improvement ] ### Todos * [ ] - Task ### What is the Jira issue? * https://jira.apache.org/jira/browse/ZEPPELIN-4509 ### How should this be tested? * CI pass ### 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: Jeff Zhang <zjf...@apache.org> Closes #3568 from zjffdu/ZEPPELIN-4509 and squashes the following commits: 2152d2f26 [Jeff Zhang] [ZEPPELIN-4509]. Make JupyterKernelInterpreter extends AbstractInterpreter --- .../zeppelin/jupyter/JupyterKernelInterpreter.java | 6 ++--- .../apache/zeppelin/jupyter/IPythonKernelTest.java | 26 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelInterpreter.java b/zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelInterpreter.java index c680f61..c38983d 100644 --- a/zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelInterpreter.java +++ b/zeppelin-jupyter-interpreter/src/main/java/org/apache/zeppelin/jupyter/JupyterKernelInterpreter.java @@ -25,8 +25,8 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.StringUtils; +import org.apache.zeppelin.interpreter.AbstractInterpreter; import org.apache.zeppelin.interpreter.BaseZeppelinContext; -import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -61,7 +61,7 @@ import java.util.Properties; * Jupyter Kernel. You can enhance the jupyter kernel by extending this class. * e.g. IPythonInterpreter. */ -public class JupyterKernelInterpreter extends Interpreter { +public class JupyterKernelInterpreter extends AbstractInterpreter { private static final Logger LOGGER = LoggerFactory.getLogger(JupyterKernelInterpreter.class); @@ -238,7 +238,7 @@ public class JupyterKernelInterpreter extends Interpreter { } @Override - public InterpreterResult interpret(String st, + public InterpreterResult internalInterpret(String st, InterpreterContext context) throws InterpreterException { zeppelinContext.setGui(context.getGui()); zeppelinContext.setNoteGui(context.getNoteGui()); diff --git a/zeppelin-jupyter-interpreter/src/test/java/org/apache/zeppelin/jupyter/IPythonKernelTest.java b/zeppelin-jupyter-interpreter/src/test/java/org/apache/zeppelin/jupyter/IPythonKernelTest.java index af8f881..59b957f 100644 --- a/zeppelin-jupyter-interpreter/src/test/java/org/apache/zeppelin/jupyter/IPythonKernelTest.java +++ b/zeppelin-jupyter-interpreter/src/test/java/org/apache/zeppelin/jupyter/IPythonKernelTest.java @@ -27,6 +27,8 @@ import org.apache.zeppelin.interpreter.InterpreterResultMessage; import org.apache.zeppelin.interpreter.LazyOpenInterpreter; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventClient; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; +import org.apache.zeppelin.resource.LocalResourcePool; +import org.apache.zeppelin.resource.ResourcePool; import org.junit.Before; import org.junit.Test; @@ -50,13 +52,16 @@ public class IPythonKernelTest { protected InterpreterGroup intpGroup; protected Interpreter interpreter; + private ResourcePool resourcePool; @Before public void setUp() throws InterpreterException { Properties properties = new Properties(); interpreter = new LazyOpenInterpreter(new JupyterInterpreter(properties)); intpGroup = new InterpreterGroup(); - intpGroup.put("session_1", new ArrayList<Interpreter>()); + resourcePool = new LocalResourcePool("local"); + intpGroup.setResourcePool(resourcePool); + intpGroup.put("session_1", new ArrayList<>()); intpGroup.get("session_1").add(interpreter); interpreter.setInterpreterGroup(intpGroup); @@ -217,7 +222,23 @@ public class IPythonKernelTest { } @Test - public void testCodeCompletion() throws InterpreterException, IOException, InterruptedException { + public void testInterpolate() throws InterpreterException, IOException { + intpGroup.getResourcePool().put("name", "hello"); + InterpreterContext context = getInterpreterContext(); + context.getLocalProperties().put("interpolate", "true"); + + String st = "print('{name}')"; + InterpreterResult result = interpreter.interpret(st, context); + + assertEquals(InterpreterResult.Code.SUCCESS, result.code()); + List<InterpreterResultMessage> interpreterResultMessages = + context.out.toInterpreterResultMessage(); + assertEquals(1, interpreterResultMessages.size()); + assertEquals("hello\n", interpreterResultMessages.get(0).getData()); + } + + @Test + public void testCodeCompletion() throws InterpreterException, InterruptedException { // define `a` first InterpreterContext context = getInterpreterContext(); String st = "a='hello'"; @@ -256,6 +277,7 @@ public class IPythonKernelTest { .setInterpreterOut(new InterpreterOutput(null)) .setIntpEventClient(mock(RemoteInterpreterEventClient.class)) .setLocalProperties(localProperties) + .setResourcePool(resourcePool) .build(); } }