Repository: zeppelin
Updated Branches:
  refs/heads/branch-0.8 eaec6dae3 -> 68b2e57b1


[ZEPPELIN-3656] Fix for completion with Livy interpreter

### What is this PR for?
Fix for NullPointerException when using code completion in the Livy Interpreter 
when Shared Interpreter is enabled.

### What type of PR is it?
Bug Fix

### What is the Jira issue?
[ZEPPELIN-3656](https://issues.apache.org/jira/browse/ZEPPELIN-3656)

### How should this be tested?
Run Livy Interpreter in an environment where Shared Interpreter is enabled and 
attempt to trigger code completions.

A unit test has been added to test the completion API when using a shared 
interpreter. Before applying the fix this test was failing with the same NPE.

### 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: Alex Bush <alex.b...@coxauto.co.uk>

Closes #3094 from alexjbush/ZEPPELIN-3656 and squashes the following commits:

4f4a875bf [Alex Bush] Correct completion test
cd0c2133f [Alex Bush] Force a failing test
71562e0f1 [Alex Bush] Test IT for Changes
32aa7c567 [Alex Bush] [ZEPPELIN-3656] Fix for completion with Livy interpreter

(cherry picked from commit 8769d41ad568155d67b5013c5e4ebe453e19190e)
Signed-off-by: Jeff Zhang <zjf...@apache.org>


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

Branch: refs/heads/branch-0.8
Commit: 68b2e57b18831f47b5c4c8204900012da30463a5
Parents: eaec6da
Author: Alex Bush <alex.b...@coxauto.co.uk>
Authored: Tue Jul 24 17:08:22 2018 +0100
Committer: Jeff Zhang <zjf...@apache.org>
Committed: Wed Jul 25 17:36:48 2018 +0800

----------------------------------------------------------------------
 .../java/org/apache/zeppelin/livy/BaseLivyInterpreter.java   | 4 ++--
 .../java/org/apache/zeppelin/livy/LivyInterpreterIT.java     | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/68b2e57b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
----------------------------------------------------------------------
diff --git 
a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java 
b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
index 079a427..75a116a 100644
--- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
+++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
@@ -271,7 +271,7 @@ public abstract class BaseLivyInterpreter extends 
Interpreter {
       candidates = callCompletion(new CompletionRequest(buf, getSessionKind(), 
cursor));
     } catch (SessionNotFoundException e) {
       LOGGER.warn("Livy session {} is expired. Will return empty list of 
candidates.",
-          sessionInfo.id);
+          getSessionInfo().id);
     } catch (LivyException le) {
       logger.error("Failed to call code completions. Will return empty list of 
candidates", le);
     }
@@ -282,7 +282,7 @@ public abstract class BaseLivyInterpreter extends 
Interpreter {
     List<InterpreterCompletion> candidates = new ArrayList<>();
     try {
       CompletionResponse resp = CompletionResponse.fromJson(
-          callRestAPI("/sessions/" + sessionInfo.id + "/completion", "POST", 
req.toJson()));
+          callRestAPI("/sessions/" + getSessionInfo().id + "/completion", 
"POST", req.toJson()));
       for (String candidate : resp.candidates) {
         candidates.add(new InterpreterCompletion(candidate, candidate, 
StringUtils.EMPTY));
       }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/68b2e57b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
----------------------------------------------------------------------
diff --git a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java 
b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
index fd3c253..37e8a99 100644
--- a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
+++ b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
@@ -31,6 +31,7 @@ import org.apache.zeppelin.interpreter.InterpreterResult;
 import org.apache.zeppelin.interpreter.InterpreterResultMessage;
 import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput;
 import org.apache.zeppelin.interpreter.LazyOpenInterpreter;
+import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -40,6 +41,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 import static org.junit.Assert.assertEquals;
@@ -771,6 +773,12 @@ public class LivyInterpreterIT {
       assertEquals(1, result.message().size());
       assertEquals(InterpreterResult.Type.IMG, 
result.message().get(0).getType());
 
+      // test code completion
+      List<InterpreterCompletion> completionResult = sparkInterpreter
+          .completion("df.sho", 6, context);
+      assertEquals(1, completionResult.size());
+      assertEquals("show", completionResult.get(0).name);
+
     } finally {
       sparkInterpreter.close();
       sqlInterpreter.close();

Reply via email to