Repository: incubator-zeppelin
Updated Branches:
  refs/heads/master 7f7a7c41a -> dd3f08e4a


ZEPPELIN-227 Allow nextline invoke in SparkInterpreter

https://issues.apache.org/jira/browse/ZEPPELIN-227

This patch allows invoke methods in nextline. To support such case

```scala
"123"
   .toInt
```

Author: Lee moon soo <[email protected]>

Closes #220 from Leemoonsoo/nextline_invoke and squashes the following commits:

0af0b9c [Lee moon soo] Fix test
3f870b3 [Lee moon soo] Nextline invoke for IgniteInterpreter
c684251 [Lee moon soo] Nextline invoke for FlinkInterpreter
fd9431a [Lee moon soo] Allow nextline invoke in SparkInterpreter


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

Branch: refs/heads/master
Commit: dd3f08e4a71c354f9cd3a1cd1524d5d51ae6571f
Parents: 7f7a7c4
Author: Lee moon soo <[email protected]>
Authored: Mon Aug 17 17:16:11 2015 -0700
Committer: Lee moon soo <[email protected]>
Committed: Thu Aug 20 15:11:40 2015 -0700

----------------------------------------------------------------------
 .../org/apache/zeppelin/flink/FlinkInterpreter.java    | 12 +++++++++++-
 .../apache/zeppelin/flink/FlinkInterpreterTest.java    |  5 +++++
 .../org/apache/zeppelin/ignite/IgniteInterpreter.java  | 12 +++++++++++-
 .../apache/zeppelin/ignite/IgniteInterpreterTest.java  |  4 ++++
 .../org/apache/zeppelin/spark/SparkInterpreter.java    | 13 ++++++++++++-
 .../apache/zeppelin/spark/SparkInterpreterTest.java    |  5 +++++
 6 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/flink/src/main/java/org/apache/zeppelin/flink/FlinkInterpreter.java
----------------------------------------------------------------------
diff --git 
a/flink/src/main/java/org/apache/zeppelin/flink/FlinkInterpreter.java 
b/flink/src/main/java/org/apache/zeppelin/flink/FlinkInterpreter.java
index c516b9d..cb861ca 100644
--- a/flink/src/main/java/org/apache/zeppelin/flink/FlinkInterpreter.java
+++ b/flink/src/main/java/org/apache/zeppelin/flink/FlinkInterpreter.java
@@ -245,7 +245,17 @@ public class FlinkInterpreter extends Interpreter {
     Code r = null;
 
     String incomplete = "";
-    for (String s : linesToRun) {
+    for (int l = 0; l < linesToRun.length; l++) {
+      String s = linesToRun[l];      
+      // check if next line starts with "." (but not ".." or "./") it is 
treated as an invocation
+      if (l + 1 < linesToRun.length) {
+        String nextLine = linesToRun[l + 1].trim();
+        if (nextLine.startsWith(".") && !nextLine.startsWith("..") && 
!nextLine.startsWith("./")) {
+          incomplete += s + "\n";
+          continue;
+        }
+      }
+
       scala.tools.nsc.interpreter.Results.Result res = null;
       try {
         res = imain.interpret(incomplete + s);

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java 
b/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java
index 64baea4..d0eda26 100644
--- a/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java
+++ b/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java
@@ -54,6 +54,11 @@ public class FlinkInterpreterTest {
     assertEquals("1", result.message());
   }
 
+  @Test
+  public void testNextlineInvoke() {
+    InterpreterResult result = flink.interpret("\"123\"\n  .toInt", context);
+    assertEquals("res0: Int = 123\n", result.message());    
+  }
 
   @Test
   public void testWordCount() {

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/ignite/src/main/java/org/apache/zeppelin/ignite/IgniteInterpreter.java
----------------------------------------------------------------------
diff --git 
a/ignite/src/main/java/org/apache/zeppelin/ignite/IgniteInterpreter.java 
b/ignite/src/main/java/org/apache/zeppelin/ignite/IgniteInterpreter.java
index e09f310..45236ab 100644
--- a/ignite/src/main/java/org/apache/zeppelin/ignite/IgniteInterpreter.java
+++ b/ignite/src/main/java/org/apache/zeppelin/ignite/IgniteInterpreter.java
@@ -286,7 +286,17 @@ public class IgniteInterpreter extends Interpreter {
     Code code = null;
 
     String incomplete = "";
-    for (String s : linesToRun) {
+    for (int l = 0; l < linesToRun.length; l++) {
+      String s = linesToRun[l];      
+      // check if next line starts with "." (but not ".." or "./") it is 
treated as an invocation
+      if (l + 1 < linesToRun.length) {
+        String nextLine = linesToRun[l + 1].trim();
+        if (nextLine.startsWith(".") && !nextLine.startsWith("..") && 
!nextLine.startsWith("./")) {
+          incomplete += s + "\n";
+          continue;
+        }
+      }
+
       try {
         code = getResultCode(imain.interpret(incomplete + s));
       } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java 
b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java
index ad393a7..081dce1 100644
--- a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java
+++ b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java
@@ -84,6 +84,9 @@ public class IgniteInterpreterTest {
 
     assertEquals(InterpreterResult.Code.SUCCESS, result.code());
     assertTrue(result.message().contains(sizeVal + ": Int = " + 
ignite.cluster().nodes().size()));
+
+    result = intp.interpret("\"123\"\n  .toInt", INTP_CONTEXT);
+    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
   }
 
   @Test
@@ -92,4 +95,5 @@ public class IgniteInterpreterTest {
 
     assertEquals(InterpreterResult.Code.ERROR, result.code());
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/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 aec6d16..a4ff494 100644
--- a/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
+++ b/spark/src/main/java/org/apache/zeppelin/spark/SparkInterpreter.java
@@ -604,7 +604,18 @@ public class SparkInterpreter extends Interpreter {
     out.reset();
     Code r = null;
     String incomplete = "";
-    for (String s : linesToRun) {
+
+    for (int l = 0; l < linesToRun.length; l++) {
+      String s = linesToRun[l];      
+      // check if next line starts with "." (but not ".." or "./") it is 
treated as an invocation
+      if (l + 1 < linesToRun.length) {
+        String nextLine = linesToRun[l + 1].trim();
+        if (nextLine.startsWith(".") && !nextLine.startsWith("..") && 
!nextLine.startsWith("./")) {
+          incomplete += s + "\n";
+          continue;
+        }
+      }
+
       scala.tools.nsc.interpreter.Results.Result res = null;
       try {
         res = intp.interpret(incomplete + s);

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/dd3f08e4/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java 
b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java
index daa7eed..87177f1 100644
--- a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java
+++ b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java
@@ -118,6 +118,11 @@ public class SparkInterpreterTest {
   }
 
   @Test
+  public void testNextLineInvocation() {
+    assertEquals(InterpreterResult.Code.SUCCESS, 
repl.interpret("\"123\"\n.toInt", context).code());    
+  }
+
+  @Test
   public void testEndWithComment() {
     assertEquals(InterpreterResult.Code.SUCCESS, repl.interpret("val 
c=1\n//comment", context).code());
   }

Reply via email to