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 2017/12/12 23:25:12 UTC

zeppelin git commit: [FIX] fix autocomplete

Repository: zeppelin
Updated Branches:
  refs/heads/master a82e3ec3a -> 4a679fc05


[FIX] fix autocomplete

### What is this PR for?
After refactoring of Interpreter autocomplete (from server side) not works without first Run of interpreter.
This PR fix it.

### What type of PR is it?
[Fix]

### How should this be tested?
* Create new Note (JDBC interpreter), try to use autocomplete (schema, tables)

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

Author: tinkoff-dwh <ti...@gmail.com>

Closes #2691 from tinkoff-dwh/fix_autocomplete and squashes the following commits:

e9bad01 [tinkoff-dwh] remove trim from completion
141dff5 [tinkoff-dwh] [FIX] fix autocomplete


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

Branch: refs/heads/master
Commit: 4a679fc055a7e6b03faa3c215562cc295714bc99
Parents: a82e3ec
Author: tinkoff-dwh <ti...@gmail.com>
Authored: Thu Dec 7 03:25:16 2017 +0500
Committer: Jeff Zhang <zj...@apache.org>
Committed: Wed Dec 13 07:25:06 2017 +0800

----------------------------------------------------------------------
 .../interpreter/remote/RemoteInterpreter.java   |  3 +-
 .../org/apache/zeppelin/notebook/Paragraph.java | 34 ++++++++------------
 .../apache/zeppelin/notebook/ParagraphTest.java |  4 +--
 3 files changed, 17 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4a679fc0/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
index 8964210..4ad36cf 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
@@ -346,8 +346,7 @@ public class RemoteInterpreter extends Interpreter {
                                                 final InterpreterContext interpreterContext)
       throws InterpreterException {
     if (!isOpened) {
-      LOGGER.warn("completion is called when RemoterInterpreter is not opened for " + className);
-      return new ArrayList<>();
+      open();
     }
     RemoteInterpreterProcess interpreterProcess = null;
     try {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4a679fc0/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
index 10a8548..5ec1329 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
@@ -191,7 +191,7 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable {
         this.scriptText = this.text.substring(headingSpace.length() + intpText.length() + 1).trim();
       } else {
         this.intpText = "";
-        this.scriptText = this.text;
+        this.scriptText = this.text.trim();
       }
     }
   }
@@ -250,14 +250,17 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable {
         return note.getInterpreterCompletion();
       }
     }
-    String trimmedBuffer = buffer != null ? buffer.trim() : null;
-    cursor = calculateCursorPosition(buffer, trimmedBuffer, cursor);
+    this.interpreter = getBindedInterpreter();
+
+    setText(buffer);
+
+    cursor = calculateCursorPosition(buffer, cursor);
 
     InterpreterContext interpreterContext = getInterpreterContextWithoutRunner(null);
 
     try {
       if (this.interpreter != null) {
-        return this.interpreter.completion(scriptText, cursor, interpreterContext);
+        return this.interpreter.completion(this.scriptText, cursor, interpreterContext);
       } else {
         return null;
       }
@@ -266,24 +269,15 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable {
     }
   }
 
-  public int calculateCursorPosition(String buffer, String trimmedBuffer, int cursor) {
-    int countWhitespacesAtStart = buffer.indexOf(trimmedBuffer);
-    if (countWhitespacesAtStart > 0) {
-      cursor -= countWhitespacesAtStart;
-    }
+  public int calculateCursorPosition(String buffer, int cursor) {
+    // scriptText trimmed
 
-    // parse text to get interpreter component
-    String repl = null;
-    if (trimmedBuffer != null) {
-      Matcher matcher = REPL_PATTERN.matcher(trimmedBuffer);
-      if (matcher.matches()) {
-        repl = matcher.group(2);
-      }
+    if (this.scriptText.isEmpty()) {
+      return 0;
     }
-
-    if (repl != null && cursor > repl.length()) {
-      String body = trimmedBuffer.substring(repl.length() + 1);
-      cursor -= repl.length() + 1 + body.indexOf(body.trim());
+    int countCharactersBeforeScript = buffer.indexOf(this.scriptText);
+    if (countCharactersBeforeScript > 0) {
+      cursor -= countCharactersBeforeScript;
     }
 
     return cursor;

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4a679fc0/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
index 9e9ce27..e46b739 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
@@ -271,7 +271,6 @@ public class ParagraphTest extends AbstractInterpreterTest {
   @Test
   public void testCursorPosition() {
     Paragraph paragraph = spy(new Paragraph());
-    doReturn(null).when(paragraph).getIntpText();
     // left = buffer, middle = cursor position into source code, right = cursor position after parse
     List<Triple<String, Integer, Integer>> dataSet = Arrays.asList(
         Triple.of("%jdbc schema.", 13, 7),
@@ -294,7 +293,8 @@ public class ParagraphTest extends AbstractInterpreterTest {
     );
 
     for (Triple<String, Integer, Integer> data : dataSet) {
-      Integer actual = paragraph.calculateCursorPosition(data.getLeft(), data.getLeft().trim(), data.getMiddle());
+      paragraph.setText(data.getLeft());
+      Integer actual = paragraph.calculateCursorPosition(data.getLeft(), data.getMiddle());
       assertEquals(data.getRight(), actual);
     }
   }