liuxunorg commented on a change in pull request #107: SUBMARINE-277. Support 
Spark Interpreter add sparkSQL interpreter
URL: https://github.com/apache/submarine/pull/107#discussion_r350595117
 
 

 ##########
 File path: 
submarine-workbench/interpreter/python-interpreter/src/main/java/org/apache/submarine/interpreter/PythonInterpreter.java
 ##########
 @@ -19,104 +19,58 @@
 package org.apache.submarine.interpreter;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.zeppelin.interpreter.InterpreterContext;
 import org.apache.zeppelin.interpreter.InterpreterException;
 import org.apache.zeppelin.interpreter.InterpreterGroup;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.util.List;
 import java.util.Properties;
 
-public class PythonInterpreter extends InterpreterProcess {
+public class PythonInterpreter extends AbstractInterpreter {
   private static final Logger LOG = 
LoggerFactory.getLogger(PythonInterpreter.class);
 
-  private org.apache.zeppelin.python.PythonInterpreter zplePythonInterpreter;
-  private InterpreterContext intpContext;
-
   public PythonInterpreter() {
     Properties properties = new Properties();
     properties = mergeZeplPyIntpProp(properties);
-    zplePythonInterpreter = new 
org.apache.zeppelin.python.PythonInterpreter(properties);
-    zplePythonInterpreter.setInterpreterGroup(new InterpreterGroup());
-    intpContext = this.getIntpContext();
+    this.zeppelinInterpreter = new 
org.apache.zeppelin.python.PythonInterpreter(properties);
+    this.zeppelinInterpreter.setInterpreterGroup(new InterpreterGroup());
   }
 
-  @Override
-  public void open() {
-    try {
-      zplePythonInterpreter.open();
-    } catch (InterpreterException e) {
-      LOG.error(e.getMessage(), e);
+  protected Properties mergeZeplPyIntpProp(Properties newProps) {
+    Properties properties = new Properties();
+    // Max number of dataframe rows to display.
+    properties.setProperty("zeppelin.python.maxResult", "1000");
+    // whether use IPython when it is available
+    properties.setProperty("zeppelin.python.useIPython", "false");
+    properties.setProperty("zeppelin.python.gatewayserver_address", 
"127.0.0.1");
+
+    if (null != newProps) {
+      newProps.putAll(properties);
+      return newProps;
+    } else {
+      return properties;
     }
   }
 
   @Override
-  public InterpreterResult interpret(String code) {
-    InterpreterResult interpreterResult = null;
+  public boolean test() {
     try {
-      org.apache.zeppelin.interpreter.InterpreterResult zeplInterpreterResult
-          = zplePythonInterpreter.interpret(code, intpContext);
-      interpreterResult = new InterpreterResult(zeplInterpreterResult);
-
-      List<org.apache.zeppelin.interpreter.InterpreterResultMessage> 
interpreterResultMessages =
-          intpContext.out.toInterpreterResultMessage();
-
-      for (org.apache.zeppelin.interpreter.InterpreterResultMessage message : 
interpreterResultMessages) {
-        interpreterResult.add(message);
+      open();
+      String code = "1 + 1";
+      InterpreterResult result = interpret(code);
+      LOG.info("Execution Python Interpreter, Calculation formula {}, Result = 
{}",
+               code, result.message().get(0).getData()
+      );
+      if (result.code() != InterpreterResult.Code.SUCCESS) {
+        return false;
       }
-    } catch (InterpreterException | IOException e) {
-      LOG.error(e.getMessage(), e);
-    }
-
-    return interpreterResult;
-  }
-
-  @Override
-  public void close() {
-    try {
-      zplePythonInterpreter.close();
-    } catch (InterpreterException e) {
-      LOG.error(e.getMessage(), e);
-    }
-  }
-
-  @Override
-  public void cancel() {
-    try {
-      zplePythonInterpreter.cancel(intpContext);
-    } catch (InterpreterException e) {
-      LOG.error(e.getMessage(), e);
-    }
-  }
-
-  @Override
-  public int getProgress() {
-    int process = 0;
-    try {
-      process = zplePythonInterpreter.getProgress(intpContext);
+      if (StringUtils.equals(result.message().get(0).getData(), "2\n")) {
+        return true;
+      }
+      return false;
     } catch (InterpreterException e) {
-      LOG.error(e.getMessage(), e);
-    }
-
-    return process;
-  }
-
-  @Override
-  public boolean test() {
-    open();
-    String code = "1 + 1";
-    InterpreterResult result = interpret(code);
-    LOG.info("Execution Python Interpreter, Calculation formula {}, Result = 
{}",
-        code, result.message().get(0).getData());
-
-    if (result.code() != InterpreterResult.Code.SUCCESS) {
+      e.printStackTrace();
 
 Review comment:
   Need change to `LOG.error(e.getMessage(), e);`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to