You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2015/12/15 02:31:41 UTC

incubator-zeppelin git commit: ZEPPELIN-496 ] Bug fixed Spark scala completion, support other interpreter issue

Repository: incubator-zeppelin
Updated Branches:
  refs/heads/master 82af1e79b -> f7e167c34


ZEPPELIN-496 ] Bug fixed Spark scala completion, support other interpreter issue

#514

RE-Fixed ZEPPELIN-485 ] Bug Fixed Paragraph Spark Completion

bug fixed, support other interpreter.
Fixed an issue that only works only on a spark..
Modify has changed in the spark-completion backend part.

For example, when you create a '% pyspark', it has been unconditionally modify the code auto-completion of the '% spark' to act according to its interpreter.

jira-issue : https://issues.apache.org/jira/browse/ZEPPELIN-496

Author: CloverHearts <es...@gmail.com>
Author: root <root@ktmedia006.(none)>

Closes #529 from cloverhearts/bug_fix/spark_completion_interpreter_bug and squashes the following commits:

53f0b10 [root] Spark completion Code style change and add length exception
477e93d [CloverHearts] remove white space
2ff9570 [CloverHearts] spark scala completion bug fix (support other interpreter)


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

Branch: refs/heads/master
Commit: f7e167c34764a0de98c7c2e140f23dc795f5e90e
Parents: 82af1e7
Author: CloverHearts <es...@gmail.com>
Authored: Mon Dec 14 11:54:46 2015 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Tue Dec 15 10:32:51 2015 +0900

----------------------------------------------------------------------
 .../apache/zeppelin/spark/SparkInterpreter.java | 51 +++++++++++++++++++-
 .../notebook/paragraph/paragraph.controller.js  | 29 +----------
 2 files changed, 51 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f7e167c3/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
----------------------------------------------------------------------
diff --git a/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java b/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
index 54691c4..095970f 100644
--- a/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
+++ b/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
@@ -580,11 +580,60 @@ public class SparkInterpreter extends Interpreter {
 
   @Override
   public List<String> completion(String buf, int cursor) {
+    if (buf.length() < cursor) {
+      cursor = buf.length();
+    }
+    String completionText = getCompletionTargetString(buf, cursor);
+    if (completionText == null) {
+      completionText = "";
+      cursor = completionText.length();
+    }
     ScalaCompleter c = completor.completer();
-    Candidates ret = c.complete(buf, cursor);
+    Candidates ret = c.complete(completionText, cursor);
     return scala.collection.JavaConversions.asJavaList(ret.candidates());
   }
 
+  private String getCompletionTargetString(String text, int cursor) {
+    String[] completionSeqCharaters = {" ", "\n", "\t"};
+    int completionEndPosition = cursor;
+    int completionStartPosition = cursor;
+    int indexOfReverseSeqPostion = cursor;
+
+    String resultCompletionText = "";
+    String completionScriptText = "";
+    try {
+      completionScriptText = text.substring(0, cursor);
+    }
+    catch (Exception e) {
+      logger.error(e.toString());
+      return null;
+    }
+    completionEndPosition = completionScriptText.length();
+
+    String tempReverseCompletionText = new StringBuilder(completionScriptText).reverse().toString();
+
+    for (String seqCharacter : completionSeqCharaters) {
+      indexOfReverseSeqPostion = tempReverseCompletionText.indexOf(seqCharacter);
+
+      if (indexOfReverseSeqPostion < completionStartPosition && indexOfReverseSeqPostion > 0) {
+        completionStartPosition = indexOfReverseSeqPostion;
+      }
+
+    }
+
+    if (completionStartPosition == completionEndPosition) {
+      completionStartPosition = 0;
+    }
+    else
+    {
+      completionStartPosition = completionEndPosition - completionStartPosition;
+    }
+    resultCompletionText = completionScriptText.substring(
+            completionStartPosition , completionEndPosition);
+
+    return resultCompletionText;
+  }
+
   public Object getValue(String name) {
     Object ret = intp.valueOfTerm(name);
     if (ret instanceof None) {

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f7e167c3/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
index dd66a59..5aff815 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
@@ -540,35 +540,8 @@ angular.module('zeppelinWebApp')
 
           pos = session.getTextRange(new Range(0, 0, pos.row, pos.column)).length;
           var buf = session.getValue();
-          var completionString = buf;
 
-          if (pos > 0) {
-            var completionStartPosition = pos;
-            var completionSeqCharaters = [' ', '\n'];
-
-            // replace \r\n or \n\r other to \n
-            var reverseCompletionString = buf.replace(/\r?\n|\r/g, '\n').substr(0, pos).split('').reverse();
-            for (var seqCharacterIndex in completionSeqCharaters) {
-              var indexOfReverseSeqPostion = reverseCompletionString.indexOf(completionSeqCharaters[seqCharacterIndex]);
-
-              if (indexOfReverseSeqPostion < completionStartPosition && indexOfReverseSeqPostion > 0) {
-                completionStartPosition = indexOfReverseSeqPostion;
-              }
-            }
-
-            if (completionStartPosition === pos) {
-              completionStartPosition = 0;
-            }
-            else
-            {
-              completionStartPosition = pos - completionStartPosition;
-            }
-
-            completionString = buf.substr( completionStartPosition , pos);
-            pos = completionString.length -1;
-          }
-
-          websocketMsgSrv.completion($scope.paragraph.id, completionString, pos);
+          websocketMsgSrv.completion($scope.paragraph.id, buf, pos);
 
           $scope.$on('completionList', function(event, data) {
             if (data.completions) {