You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2018/08/26 04:44:24 UTC
[41/49] zeppelin git commit: [ZEPPELIN-3740] Adopt
`google-java-format` and `fmt-maven-plugin`
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 4504089..be700c3 100644
--- a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
+++ b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
@@ -17,6 +17,14 @@
package org.apache.zeppelin.livy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.livy.test.framework.Cluster;
import org.apache.livy.test.framework.Cluster$;
@@ -37,15 +45,6 @@ import org.junit.Test;
import org.slf4j.Logger;
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;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
public class LivyInterpreterIT {
private static final Logger LOGGER = LoggerFactory.getLogger(LivyInterpreterIT.class);
private static Cluster cluster;
@@ -85,7 +84,6 @@ public class LivyInterpreterIT {
return true;
}
-
@Test
public void testSparkInterpreter() throws InterpreterException {
if (!checkPreCondition()) {
@@ -99,12 +97,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
sparkInterpreter.open();
LivySparkSQLInterpreter sqlInterpreter = new LivySparkSQLInterpreter(properties);
@@ -132,12 +131,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- final InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ final InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
;
InterpreterResult result = sparkInterpreter.interpret("sc.parallelize(1 to 10).sum()", context);
@@ -158,18 +158,15 @@ public class LivyInterpreterIT {
assertEquals(1, result.message().size());
// multi-line string
- String multiLineString = "val str = \"\"\"multiple\n" +
- "line\"\"\"\n" +
- "println(str)";
+ String multiLineString = "val str = \"\"\"multiple\n" + "line\"\"\"\n" + "println(str)";
result = sparkInterpreter.interpret(multiLineString, context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
assertTrue(result.message().get(0).getData().contains("multiple\nline"));
// case class
- String caseClassCode = "case class Person(id:Int, \n" +
- "name:String)\n" +
- "val p=Person(1, \"name_a\")";
+ String caseClassCode =
+ "case class Person(id:Int, \n" + "name:String)\n" + "val p=Person(1, \"name_a\")";
result = sparkInterpreter.interpret(caseClassCode, context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
@@ -207,60 +204,78 @@ public class LivyInterpreterIT {
// cancel
if (sparkInterpreter.livyVersion.newerThanEquals(LivyVersion.LIVY_0_3_0)) {
- Thread cancelThread = new Thread() {
- @Override
- public void run() {
- // invoke cancel after 1 millisecond to wait job starting
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- sparkInterpreter.cancel(context);
- }
- };
+ Thread cancelThread =
+ new Thread() {
+ @Override
+ public void run() {
+ // invoke cancel after 1 millisecond to wait job starting
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ sparkInterpreter.cancel(context);
+ }
+ };
cancelThread.start();
- result = sparkInterpreter
- .interpret("sc.parallelize(1 to 10).foreach(e=>Thread.sleep(10*1000))", context);
+ result =
+ sparkInterpreter.interpret(
+ "sc.parallelize(1 to 10).foreach(e=>Thread.sleep(10*1000))", context);
assertEquals(InterpreterResult.Code.ERROR, result.code());
String message = result.message().get(0).getData();
// 2 possibilities, sometimes livy doesn't return the real cancel exception
- assertTrue(message.contains("cancelled part of cancelled job group") ||
- message.contains("Job is cancelled"));
+ assertTrue(
+ message.contains("cancelled part of cancelled job group")
+ || message.contains("Job is cancelled"));
}
}
- private void testDataFrame(LivySparkInterpreter sparkInterpreter,
- final LivySparkSQLInterpreter sqlInterpreter,
- boolean isSpark2) throws LivyException {
+ private void testDataFrame(
+ LivySparkInterpreter sparkInterpreter,
+ final LivySparkSQLInterpreter sqlInterpreter,
+ boolean isSpark2)
+ throws LivyException {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- final InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ final InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
InterpreterResult result = null;
// test DataFrame api
if (!isSpark2) {
- result = sparkInterpreter.interpret(
- "val df=sqlContext.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=sqlContext.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
} else {
- result = sparkInterpreter.interpret(
- "val df=spark.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=spark.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
}
sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
// test LivySparkSQLInterpreter which share the same SparkContext with LivySparkInterpreter
@@ -299,57 +314,70 @@ public class LivyInterpreterIT {
// test sql cancel
if (sqlInterpreter.getLivyVersion().newerThanEquals(LivyVersion.LIVY_0_3_0)) {
- Thread cancelThread = new Thread() {
- @Override
- public void run() {
- sqlInterpreter.cancel(context);
- }
- };
+ Thread cancelThread =
+ new Thread() {
+ @Override
+ public void run() {
+ sqlInterpreter.cancel(context);
+ }
+ };
cancelThread.start();
- //sleep so that cancelThread performs a cancel.
+ // sleep so that cancelThread performs a cancel.
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
- result = sqlInterpreter
- .interpret("select count(1) from df", context);
+ result = sqlInterpreter.interpret("select count(1) from df", context);
if (result.code().equals(InterpreterResult.Code.ERROR)) {
String message = result.message().get(0).getData();
// 2 possibilities, sometimes livy doesn't return the real cancel exception
- assertTrue(message.contains("cancelled part of cancelled job group") ||
- message.contains("Job is cancelled"));
+ assertTrue(
+ message.contains("cancelled part of cancelled job group")
+ || message.contains("Job is cancelled"));
}
}
// test result string truncate
if (!isSpark2) {
- result = sparkInterpreter.interpret(
- "val df=sqlContext.createDataFrame(Seq((\"12characters12characters\",20)))"
- + ".toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=sqlContext.createDataFrame(Seq((\"12characters12characters\",20)))"
+ + ".toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
} else {
- result = sparkInterpreter.interpret(
- "val df=spark.createDataFrame(Seq((\"12characters12characters\",20)))"
- + ".toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=spark.createDataFrame(Seq((\"12characters12characters\",20)))"
+ + ".toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
}
sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
// test LivySparkSQLInterpreter which share the same SparkContext with LivySparkInterpreter
- result = sqlInterpreter.interpret("select * from df where col_1='12characters12characters'",
- context);
+ result =
+ sqlInterpreter.interpret(
+ "select * from df where col_1='12characters12characters'", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
assertEquals("col_1\tcol_2\n12characters12cha...\t20", result.message().get(0).getData());
-
}
@Test
@@ -363,12 +391,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- final InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ final InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
pysparkInterpreter.open();
// test traceback msg
@@ -376,8 +405,8 @@ public class LivyInterpreterIT {
pysparkInterpreter.getLivyVersion();
// for livy version >=0.3 , input some erroneous spark code, check the shown result is more
// than one line
- InterpreterResult result = pysparkInterpreter.interpret(
- "sc.parallelize(wrongSyntax(1, 2)).count()", context);
+ InterpreterResult result =
+ pysparkInterpreter.interpret("sc.parallelize(wrongSyntax(1, 2)).count()", context);
assertEquals(InterpreterResult.Code.ERROR, result.code());
assertTrue(result.message().get(0).getData().split("\n").length > 1);
assertTrue(result.message().get(0).getData().contains("Traceback"));
@@ -397,7 +426,7 @@ public class LivyInterpreterIT {
assertEquals(InterpreterResult.Code.SUCCESS, reslt.code());
assertTrue(reslt.message().get(0).getData().contains(utf8Str));
- //test special characters
+ // test special characters
String charStr = "açñiñíûÑoç";
InterpreterResult res = pysparkInterpreter.interpret("print(\"" + charStr + "\")", context);
assertEquals(InterpreterResult.Code.SUCCESS, res.code());
@@ -418,28 +447,34 @@ public class LivyInterpreterIT {
// test DataFrame api
if (!isSpark2) {
- pysparkInterpreter.interpret("from pyspark.sql import SQLContext\n"
- + "sqlContext = SQLContext(sc)", context);
- result = pysparkInterpreter.interpret("df=sqlContext.createDataFrame([(\"hello\",20)])\n"
- + "df.collect()", context);
+ pysparkInterpreter.interpret(
+ "from pyspark.sql import SQLContext\n" + "sqlContext = SQLContext(sc)", context);
+ result =
+ pysparkInterpreter.interpret(
+ "df=sqlContext.createDataFrame([(\"hello\",20)])\n" + "df.collect()", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- //python2 has u and python3 don't have u
- assertTrue(result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]")
- || result.message().get(0).getData().contains("[Row(_1='hello', _2=20)]"));
+ // python2 has u and python3 don't have u
+ assertTrue(
+ result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]")
+ || result.message().get(0).getData().contains("[Row(_1='hello', _2=20)]"));
} else {
- result = pysparkInterpreter.interpret("df=spark.createDataFrame([(\"hello\",20)])\n"
- + "df.collect()", context);
+ result =
+ pysparkInterpreter.interpret(
+ "df=spark.createDataFrame([(\"hello\",20)])\n" + "df.collect()", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- //python2 has u and python3 don't have u
- assertTrue(result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]")
- || result.message().get(0).getData().contains("[Row(_1='hello', _2=20)]"));
+ // python2 has u and python3 don't have u
+ assertTrue(
+ result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]")
+ || result.message().get(0).getData().contains("[Row(_1='hello', _2=20)]"));
}
// test magic api
- pysparkInterpreter.interpret("t = [{\"name\":\"userA\", \"role\":\"roleA\"},"
- + "{\"name\":\"userB\", \"role\":\"roleB\"}]", context);
+ pysparkInterpreter.interpret(
+ "t = [{\"name\":\"userA\", \"role\":\"roleA\"},"
+ + "{\"name\":\"userB\", \"role\":\"roleB\"}]",
+ context);
result = pysparkInterpreter.interpret("%table t", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
@@ -454,27 +489,29 @@ public class LivyInterpreterIT {
// cancel
if (pysparkInterpreter.livyVersion.newerThanEquals(LivyVersion.LIVY_0_3_0)) {
- Thread cancelThread = new Thread() {
- @Override
- public void run() {
- // invoke cancel after 1 millisecond to wait job starting
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- pysparkInterpreter.cancel(context);
- }
- };
+ Thread cancelThread =
+ new Thread() {
+ @Override
+ public void run() {
+ // invoke cancel after 1 millisecond to wait job starting
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ pysparkInterpreter.cancel(context);
+ }
+ };
cancelThread.start();
- result = pysparkInterpreter
- .interpret("import time\n" +
- "sc.range(1, 10).foreach(lambda a: time.sleep(10))", context);
+ result =
+ pysparkInterpreter.interpret(
+ "import time\n" + "sc.range(1, 10).foreach(lambda a: time.sleep(10))", context);
assertEquals(InterpreterResult.Code.ERROR, result.code());
String message = result.message().get(0).getData();
// 2 possibilities, sometimes livy doesn't return the real cancel exception
- assertTrue(message.contains("cancelled part of cancelled job group") ||
- message.contains("Job is cancelled"));
+ assertTrue(
+ message.contains("cancelled part of cancelled job group")
+ || message.contains("Job is cancelled"));
}
} finally {
pysparkInterpreter.close();
@@ -500,12 +537,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
sparkInterpreter.open();
LivySparkSQLInterpreter sqlInterpreter = new LivySparkSQLInterpreter(properties2);
@@ -535,28 +573,43 @@ public class LivyInterpreterIT {
boolean isSpark2 = isSpark2(sparkInterpreter, context);
if (!isSpark2) {
- result = sparkInterpreter.interpret(
- "val df=sqlContext.createDataFrame(Seq((\"12characters12characters\",20)))"
- + ".toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=sqlContext.createDataFrame(Seq((\"12characters12characters\",20)))"
+ + ".toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(2, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains(
+ "Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
} else {
- result = sparkInterpreter.interpret(
- "val df=spark.createDataFrame(Seq((\"12characters12characters\",20)))"
- + ".toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=spark.createDataFrame(Seq((\"12characters12characters\",20)))"
+ + ".toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(2, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains(
+ "Array[org.apache.spark.sql.Row] = Array([12characters12characters,20])"));
}
sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
// test LivySparkSQLInterpreter which share the same SparkContext with LivySparkInterpreter
- result = sqlInterpreter.interpret("select * from df where col_1='12characters12characters'",
- context);
+ result =
+ sqlInterpreter.interpret(
+ "select * from df where col_1='12characters12characters'", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
assertEquals("col_1\tcol_2\n12characters12characters\t20", result.message().get(0).getData());
@@ -584,12 +637,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- final InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ final InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
sparkRInterpreter.open();
try {
@@ -604,30 +658,36 @@ public class LivyInterpreterIT {
assertTrue(result.message().get(0).getData().contains("eruptions waiting"));
// cancel
- Thread cancelThread = new Thread() {
- @Override
- public void run() {
- // invoke cancel after 1 millisecond to wait job starting
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- sparkRInterpreter.cancel(context);
- }
- };
+ Thread cancelThread =
+ new Thread() {
+ @Override
+ public void run() {
+ // invoke cancel after 1 millisecond to wait job starting
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ sparkRInterpreter.cancel(context);
+ }
+ };
cancelThread.start();
- result = sparkRInterpreter.interpret("df <- as.DataFrame(faithful)\n" +
- "df1 <- dapplyCollect(df, function(x) " +
- "{ Sys.sleep(10); x <- cbind(x, x$waiting * 60) })", context);
+ result =
+ sparkRInterpreter.interpret(
+ "df <- as.DataFrame(faithful)\n"
+ + "df1 <- dapplyCollect(df, function(x) "
+ + "{ Sys.sleep(10); x <- cbind(x, x$waiting * 60) })",
+ context);
assertEquals(InterpreterResult.Code.ERROR, result.code());
String message = result.message().get(0).getData();
// 2 possibilities, sometimes livy doesn't return the real cancel exception
- assertTrue(message.contains("cancelled part of cancelled job group") ||
- message.contains("Job is cancelled"));
+ assertTrue(
+ message.contains("cancelled part of cancelled job group")
+ || message.contains("Job is cancelled"));
} else {
- result = sparkRInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)" +
- "\nhead(df)", context);
+ result =
+ sparkRInterpreter.interpret(
+ "df <- createDataFrame(sqlContext, faithful)" + "\nhead(df)", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
assertTrue(result.message().get(0).getData().contains("eruptions waiting"));
@@ -650,12 +710,12 @@ public class LivyInterpreterIT {
}
InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
interpreterGroup.put("session_1", new ArrayList<Interpreter>());
- LazyOpenInterpreter sparkInterpreter = new LazyOpenInterpreter(
- new LivySparkInterpreter(properties));
+ LazyOpenInterpreter sparkInterpreter =
+ new LazyOpenInterpreter(new LivySparkInterpreter(properties));
sparkInterpreter.setInterpreterGroup(interpreterGroup);
interpreterGroup.get("session_1").add(sparkInterpreter);
- LazyOpenInterpreter sqlInterpreter = new LazyOpenInterpreter(
- new LivySparkSQLInterpreter(properties));
+ LazyOpenInterpreter sqlInterpreter =
+ new LazyOpenInterpreter(new LivySparkSQLInterpreter(properties));
interpreterGroup.get("session_1").add(sqlInterpreter);
sqlInterpreter.setInterpreterGroup(interpreterGroup);
sqlInterpreter.open();
@@ -664,12 +724,13 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
String p1 = IOUtils.toString(getClass().getResourceAsStream("/livy_tutorial_1.scala"));
InterpreterResult result = sparkInterpreter.interpret(p1, context);
@@ -692,28 +753,28 @@ public class LivyInterpreterIT {
}
InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
interpreterGroup.put("session_1", new ArrayList<Interpreter>());
- LazyOpenInterpreter sparkInterpreter = new LazyOpenInterpreter(
- new LivySparkInterpreter(properties));
+ LazyOpenInterpreter sparkInterpreter =
+ new LazyOpenInterpreter(new LivySparkInterpreter(properties));
sparkInterpreter.setInterpreterGroup(interpreterGroup);
interpreterGroup.get("session_1").add(sparkInterpreter);
- LazyOpenInterpreter sqlInterpreter = new LazyOpenInterpreter(
- new LivySparkSQLInterpreter(properties));
+ LazyOpenInterpreter sqlInterpreter =
+ new LazyOpenInterpreter(new LivySparkSQLInterpreter(properties));
interpreterGroup.get("session_1").add(sqlInterpreter);
sqlInterpreter.setInterpreterGroup(interpreterGroup);
- LazyOpenInterpreter pysparkInterpreter = new LazyOpenInterpreter(
- new LivyPySparkInterpreter(properties));
+ LazyOpenInterpreter pysparkInterpreter =
+ new LazyOpenInterpreter(new LivyPySparkInterpreter(properties));
interpreterGroup.get("session_1").add(pysparkInterpreter);
pysparkInterpreter.setInterpreterGroup(interpreterGroup);
- LazyOpenInterpreter sparkRInterpreter = new LazyOpenInterpreter(
- new LivySparkRInterpreter(properties));
+ LazyOpenInterpreter sparkRInterpreter =
+ new LazyOpenInterpreter(new LivySparkRInterpreter(properties));
interpreterGroup.get("session_1").add(sparkRInterpreter);
sparkRInterpreter.setInterpreterGroup(interpreterGroup);
- LazyOpenInterpreter sharedInterpreter = new LazyOpenInterpreter(
- new LivySharedInterpreter(properties));
+ LazyOpenInterpreter sharedInterpreter =
+ new LazyOpenInterpreter(new LivySharedInterpreter(properties));
interpreterGroup.get("session_1").add(sharedInterpreter);
sharedInterpreter.setInterpreterGroup(interpreterGroup);
@@ -726,68 +787,91 @@ public class LivyInterpreterIT {
AuthenticationInfo authInfo = new AuthenticationInfo("user1");
MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
InterpreterOutput output = new InterpreterOutput(outputListener);
- InterpreterContext context = InterpreterContext.builder()
- .setNoteId("noteId")
- .setParagraphId("paragraphId")
- .setAuthenticationInfo(authInfo)
- .setInterpreterOut(output)
- .build();
+ InterpreterContext context =
+ InterpreterContext.builder()
+ .setNoteId("noteId")
+ .setParagraphId("paragraphId")
+ .setAuthenticationInfo(authInfo)
+ .setInterpreterOut(output)
+ .build();
// detect spark version
InterpreterResult result = sparkInterpreter.interpret("sc.version", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- boolean isSpark2 = isSpark2((BaseLivyInterpreter) sparkInterpreter.getInnerInterpreter(),
- context);
+ boolean isSpark2 =
+ isSpark2((BaseLivyInterpreter) sparkInterpreter.getInnerInterpreter(), context);
if (!isSpark2) {
- result = sparkInterpreter.interpret(
- "val df=sqlContext.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=sqlContext.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
// access table from pyspark
- result = pysparkInterpreter.interpret("sqlContext.sql(\"select * from df\").show()",
- context);
+ result =
+ pysparkInterpreter.interpret("sqlContext.sql(\"select * from df\").show()", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("+-----+-----+\n" +
- "|col_1|col_2|\n" +
- "+-----+-----+\n" +
- "|hello| 20|\n" +
- "+-----+-----+"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains(
+ "+-----+-----+\n"
+ + "|col_1|col_2|\n"
+ + "+-----+-----+\n"
+ + "|hello| 20|\n"
+ + "+-----+-----+"));
// access table from sparkr
- result = sparkRInterpreter.interpret("head(sql(sqlContext, \"select * from df\"))",
- context);
+ result =
+ sparkRInterpreter.interpret("head(sql(sqlContext, \"select * from df\"))", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
assertTrue(result.message().get(0).getData().contains("col_1 col_2\n1 hello 20"));
} else {
- result = sparkInterpreter.interpret(
- "val df=spark.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
- + "df.collect()", context);
+ result =
+ sparkInterpreter.interpret(
+ "val df=spark.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
+ + "df.collect()",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
// access table from pyspark
result = pysparkInterpreter.interpret("spark.sql(\"select * from df\").show()", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
- assertTrue(result.message().get(0).getData()
- .contains("+-----+-----+\n" +
- "|col_1|col_2|\n" +
- "+-----+-----+\n" +
- "|hello| 20|\n" +
- "+-----+-----+"));
+ assertTrue(
+ result
+ .message()
+ .get(0)
+ .getData()
+ .contains(
+ "+-----+-----+\n"
+ + "|col_1|col_2|\n"
+ + "+-----+-----+\n"
+ + "|hello| 20|\n"
+ + "+-----+-----+"));
// access table from sparkr
result = sparkRInterpreter.interpret("head(sql(\"select * from df\"))", context);
@@ -797,27 +881,28 @@ public class LivyInterpreterIT {
}
// test plotting of python
- result = pysparkInterpreter.interpret(
- "import matplotlib.pyplot as plt\n" +
- "plt.switch_backend('agg')\n" +
- "data=[1,2,3,4]\n" +
- "plt.figure()\n" +
- "plt.plot(data)\n" +
- "%matplot plt", context);
+ result =
+ pysparkInterpreter.interpret(
+ "import matplotlib.pyplot as plt\n"
+ + "plt.switch_backend('agg')\n"
+ + "data=[1,2,3,4]\n"
+ + "plt.figure()\n"
+ + "plt.plot(data)\n"
+ + "%matplot plt",
+ context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
assertEquals(InterpreterResult.Type.IMG, result.message().get(0).getType());
// test plotting of R
- result = sparkRInterpreter.interpret(
- "hist(mtcars$mpg)", context);
+ result = sparkRInterpreter.interpret("hist(mtcars$mpg)", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
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);
+ List<InterpreterCompletion> completionResult =
+ sparkInterpreter.completion("df.sho", 6, context);
assertEquals(1, completionResult.size());
assertEquals("show", completionResult.get(0).name);
@@ -849,17 +934,12 @@ public class LivyInterpreterIT {
public static class MyInterpreterOutputListener implements InterpreterOutputListener {
@Override
- public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
- }
+ public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {}
@Override
- public void onUpdate(int index, InterpreterResultMessageOutput out) {
-
- }
+ public void onUpdate(int index, InterpreterResultMessageOutput out) {}
@Override
- public void onUpdateAll(InterpreterOutput out) {
-
- }
+ public void onUpdateAll(InterpreterOutput out) {}
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java
----------------------------------------------------------------------
diff --git a/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java b/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java
index 8821a86..8e1a83d 100644
--- a/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java
+++ b/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java
@@ -21,15 +21,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
-
import java.util.List;
import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
-/**
- * Unit test for LivySQLInterpreter.
- */
+/** Unit test for LivySQLInterpreter. */
public class LivySQLInterpreterTest {
private LivySparkSQLInterpreter sqlInterpreter;
@@ -58,14 +55,11 @@ public class LivySQLInterpreterTest {
// | a| b|
// +---+---+
// +---+---+
- List<String> rows = sqlInterpreter.parseSQLOutput("+---+---+\n" +
- "| a| b|\n" +
- "+---+---+\n" +
- "+---+---+");
+ List<String> rows =
+ sqlInterpreter.parseSQLOutput("+---+---+\n" + "| a| b|\n" + "+---+---+\n" + "+---+---+");
assertEquals(1, rows.size());
assertEquals("a\tb", rows.get(0));
-
// sql output with 2 rows
// +---+---+
// | a| b|
@@ -73,18 +67,19 @@ public class LivySQLInterpreterTest {
// | 1| 1a|
// | 2| 2b|
// +---+---+
- rows = sqlInterpreter.parseSQLOutput("+---+---+\n" +
- "| a| b|\n" +
- "+---+---+\n" +
- "| 1| 1a|\n" +
- "| 2| 2b|\n" +
- "+---+---+");
+ rows =
+ sqlInterpreter.parseSQLOutput(
+ "+---+---+\n"
+ + "| a| b|\n"
+ + "+---+---+\n"
+ + "| 1| 1a|\n"
+ + "| 2| 2b|\n"
+ + "+---+---+");
assertEquals(3, rows.size());
assertEquals("a\tb", rows.get(0));
assertEquals("1\t1a", rows.get(1));
assertEquals("2\t2b", rows.get(2));
-
// sql output with 3 rows and showing "only showing top 3 rows"
// +---+---+
// | a| b|
@@ -94,21 +89,22 @@ public class LivySQLInterpreterTest {
// | 3| 3c|
// +---+---+
// only showing top 3 rows
- rows = sqlInterpreter.parseSQLOutput("+---+---+\n" +
- "| a| b|\n" +
- "+---+---+\n" +
- "| 1| 1a|\n" +
- "| 2| 2b|\n" +
- "| 3| 3c|\n" +
- "+---+---+\n" +
- "only showing top 3 rows");
+ rows =
+ sqlInterpreter.parseSQLOutput(
+ "+---+---+\n"
+ + "| a| b|\n"
+ + "+---+---+\n"
+ + "| 1| 1a|\n"
+ + "| 2| 2b|\n"
+ + "| 3| 3c|\n"
+ + "+---+---+\n"
+ + "only showing top 3 rows");
assertEquals(4, rows.size());
assertEquals("a\tb", rows.get(0));
assertEquals("1\t1a", rows.get(1));
assertEquals("2\t2b", rows.get(2));
assertEquals("3\t3c", rows.get(3));
-
// sql output with 1 rows and showing "only showing top 1 rows"
// +---+
// | a|
@@ -116,17 +112,13 @@ public class LivySQLInterpreterTest {
// | 1|
// +---+
// only showing top 1 rows
- rows = sqlInterpreter.parseSQLOutput("+---+\n" +
- "| a|\n" +
- "+---+\n" +
- "| 1|\n" +
- "+---+\n" +
- "only showing top 1 rows");
+ rows =
+ sqlInterpreter.parseSQLOutput(
+ "+---+\n" + "| a|\n" + "+---+\n" + "| 1|\n" + "+---+\n" + "only showing top 1 rows");
assertEquals(2, rows.size());
assertEquals("a", rows.get(0));
assertEquals("1", rows.get(1));
-
// sql output with 3 rows, 3 columns, showing "only showing top 3 rows" with a line break in
// the data
// +---+---+---+
@@ -138,21 +130,22 @@ public class LivySQLInterpreterTest {
// | 3a| 3b| 3c|
// +---+---+---+
// only showing top 3 rows
- rows = sqlInterpreter.parseSQLOutput("+---+----+---+\n" +
- "| a| b| c|\n" +
- "+---+----+---+\n" +
- "| 1a| 1b| 1c|\n" +
- "| 2a| 2\nb| 2c|\n" +
- "| 3a| 3b| 3c|\n" +
- "+---+---+---+\n" +
- "only showing top 3 rows");
+ rows =
+ sqlInterpreter.parseSQLOutput(
+ "+---+----+---+\n"
+ + "| a| b| c|\n"
+ + "+---+----+---+\n"
+ + "| 1a| 1b| 1c|\n"
+ + "| 2a| 2\nb| 2c|\n"
+ + "| 3a| 3b| 3c|\n"
+ + "+---+---+---+\n"
+ + "only showing top 3 rows");
assertEquals(4, rows.size());
assertEquals("a\tb\tc", rows.get(0));
assertEquals("1a\t1b\t1c", rows.get(1));
assertEquals("2a\t2\\nb\t2c", rows.get(2));
assertEquals("3a\t3b\t3c", rows.get(3));
-
// sql output with 2 rows and one containing a tab
// +---+---+
// | a| b|
@@ -160,12 +153,14 @@ public class LivySQLInterpreterTest {
// | 1| \ta|
// | 2| 2b|
// +---+---+
- rows = sqlInterpreter.parseSQLOutput("+---+---+\n" +
- "| a| b|\n" +
- "+---+---+\n" +
- "| 1| \ta|\n" +
- "| 2| 2b|\n" +
- "+---+---+");
+ rows =
+ sqlInterpreter.parseSQLOutput(
+ "+---+---+\n"
+ + "| a| b|\n"
+ + "+---+---+\n"
+ + "| 1| \ta|\n"
+ + "| 2| 2b|\n"
+ + "+---+---+");
assertEquals(3, rows.size());
assertEquals("a\tb", rows.get(0));
assertEquals("1\t\\ta", rows.get(1));
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/pom.xml
----------------------------------------------------------------------
diff --git a/markdown/pom.xml b/markdown/pom.xml
index 79cabc1..dce5157 100644
--- a/markdown/pom.xml
+++ b/markdown/pom.xml
@@ -93,13 +93,6 @@
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown.java b/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown.java
index 83b4069..233dd16 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown.java
@@ -17,12 +17,8 @@
package org.apache.zeppelin.markdown;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.List;
import java.util.Properties;
-
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterResult;
@@ -31,18 +27,16 @@ import org.apache.zeppelin.interpreter.InterpreterUtils;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-/**
- * MarkdownInterpreter interpreter for Zeppelin.
- */
+/** MarkdownInterpreter interpreter for Zeppelin. */
public class Markdown extends Interpreter {
private static final Logger LOGGER = LoggerFactory.getLogger(Markdown.class);
private MarkdownParser parser;
- /**
- * Markdown Parser Type.
- */
+ /** Markdown Parser Type. */
public enum MarkdownParserType {
PEGDOWN {
@Override
@@ -85,8 +79,7 @@ public class Markdown extends Interpreter {
}
@Override
- public void close() {
- }
+ public void close() {}
@Override
public InterpreterResult interpret(String markdownText, InterpreterContext interpreterContext) {
@@ -103,8 +96,7 @@ public class Markdown extends Interpreter {
}
@Override
- public void cancel(InterpreterContext context) {
- }
+ public void cancel(InterpreterContext context) {}
@Override
public FormType getFormType() {
@@ -123,8 +115,8 @@ public class Markdown extends Interpreter {
}
@Override
- public List<InterpreterCompletion> completion(String buf, int cursor,
- InterpreterContext interpreterContext) {
+ public List<InterpreterCompletion> completion(
+ String buf, int cursor, InterpreterContext interpreterContext) {
return null;
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown4jParser.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown4jParser.java b/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown4jParser.java
index 215540d..77fd4a3 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown4jParser.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/Markdown4jParser.java
@@ -17,13 +17,10 @@
package org.apache.zeppelin.markdown;
-import org.markdown4j.Markdown4jProcessor;
-
import java.io.IOException;
+import org.markdown4j.Markdown4jProcessor;
-/**
- * Markdown Parser using markdown4j processor.
- */
+/** Markdown Parser using markdown4j processor. */
public class Markdown4jParser implements MarkdownParser {
private Markdown4jProcessor processor;
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/MarkdownParser.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/MarkdownParser.java b/markdown/src/main/java/org/apache/zeppelin/markdown/MarkdownParser.java
index 2f8717e..056ca26 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/MarkdownParser.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/MarkdownParser.java
@@ -17,9 +17,7 @@
package org.apache.zeppelin.markdown;
-/**
- * Abstract Markdown Parser.
- */
+/** Abstract Markdown Parser. */
public interface MarkdownParser {
String render(String markdownText);
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.java b/markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.java
index 14828e0..37b864e 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.java
@@ -17,10 +17,9 @@
package org.apache.zeppelin.markdown;
-import org.parboiled.support.Var;
-
import java.util.HashMap;
import java.util.Map;
+import org.parboiled.support.Var;
/**
* Implementation of Var to support parameter parsing.
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownParser.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownParser.java b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownParser.java
index fb99f05..3152f99 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownParser.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownParser.java
@@ -21,9 +21,7 @@ import org.pegdown.Extensions;
import org.pegdown.PegDownProcessor;
import org.pegdown.plugins.PegDownPlugins;
-/**
- * Markdown Parser using pegdown processor.
- */
+/** Markdown Parser using pegdown processor. */
public class PegdownParser implements MarkdownParser {
private PegDownProcessor processor;
@@ -31,10 +29,11 @@ public class PegdownParser implements MarkdownParser {
public static final int OPTIONS = Extensions.ALL_WITH_OPTIONALS - Extensions.ANCHORLINKS;
public PegdownParser() {
- PegDownPlugins plugins = new PegDownPlugins.Builder()
- .withPlugin(PegdownYumlPlugin.class)
- .withPlugin(PegdownWebSequencelPlugin.class)
- .build();
+ PegDownPlugins plugins =
+ new PegDownPlugins.Builder()
+ .withPlugin(PegdownYumlPlugin.class)
+ .withPlugin(PegdownWebSequencelPlugin.class)
+ .build();
processor = new PegDownProcessor(OPTIONS, PARSING_TIMEOUT_AS_MILLIS, plugins);
}
@@ -53,9 +52,7 @@ public class PegdownParser implements MarkdownParser {
return html;
}
- /**
- * wrap with markdown class div to styling DOM using css.
- */
+ /** wrap with markdown class div to styling DOM using css. */
public static String wrapWithMarkdownClassDiv(String html) {
return new StringBuilder()
.append("<div class=\"markdown-body\">\n")
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.java b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.java
index 6238f95..88184df 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.java
@@ -17,6 +17,14 @@
package org.apache.zeppelin.markdown;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.parboiled.BaseParser;
@@ -28,29 +36,17 @@ import org.pegdown.ast.TextNode;
import org.pegdown.plugins.BlockPluginParser;
import org.pegdown.plugins.PegDownPlugins;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-
-/**
- * Pegdown plugin for Websequence diagram.
- */
+/** Pegdown plugin for Websequence diagram. */
public class PegdownWebSequencelPlugin extends Parser implements BlockPluginParser {
private static final String WEBSEQ_URL = "http://www.websequencediagrams.com";
public PegdownWebSequencelPlugin() {
- super(PegdownParser.OPTIONS,
- PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
- DefaultParseRunnerProvider);
+ super(
+ PegdownParser.OPTIONS, PegdownParser.PARSING_TIMEOUT_AS_MILLIS, DefaultParseRunnerProvider);
}
- public PegdownWebSequencelPlugin(Integer opts, Long millis, ParseRunnerProvider provider,
- PegDownPlugins plugins) {
+ public PegdownWebSequencelPlugin(
+ Integer opts, Long millis, ParseRunnerProvider provider, PegDownPlugins plugins) {
super(opts, millis, provider, plugins);
}
@@ -74,16 +70,14 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
return NodeSequence(
startMarker(),
- Optional(
- String("style="),
- Sequence(OneOrMore(Letter()), style.append(match()), Spn1())),
+ Optional(String("style="), Sequence(OneOrMore(Letter()), style.append(match()), Spn1())),
Sequence(body(), body.append(match())),
endMarker(),
push(
- new ExpImageNode("title",
+ new ExpImageNode(
+ "title",
createWebsequenceUrl(style.getString(), body.getString()),
- new TextNode("")))
- );
+ new TextNode(""))));
}
public static String createWebsequenceUrl(String style, String content) {
@@ -95,13 +89,14 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
String webSeqUrl = "";
try {
- String query = new StringBuilder()
- .append("style=")
- .append(style)
- .append("&message=")
- .append(URLEncoder.encode(content, "UTF-8"))
- .append("&apiVersion=1")
- .toString();
+ String query =
+ new StringBuilder()
+ .append("style=")
+ .append(style)
+ .append("&message=")
+ .append(URLEncoder.encode(content, "UTF-8"))
+ .append("&apiVersion=1")
+ .toString();
URL url = new URL(WEBSEQ_URL);
URLConnection conn = url.openConnection();
@@ -111,8 +106,8 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
writer.flush();
StringBuilder response = new StringBuilder();
- reader = new BufferedReader(
- new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
+ reader =
+ new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
@@ -141,6 +136,6 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
@Override
public Rule[] blockPluginRules() {
- return new Rule[]{blockRule()};
+ return new Rule[] {blockRule()};
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownYumlPlugin.java
----------------------------------------------------------------------
diff --git a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownYumlPlugin.java b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownYumlPlugin.java
index c9e942a..e9ac9ad 100644
--- a/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownYumlPlugin.java
+++ b/markdown/src/main/java/org/apache/zeppelin/markdown/PegdownYumlPlugin.java
@@ -19,6 +19,9 @@ package org.apache.zeppelin.markdown;
import static org.apache.commons.lang3.StringUtils.defaultString;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Map;
import org.parboiled.BaseParser;
import org.parboiled.Rule;
import org.parboiled.support.StringBuilderVar;
@@ -28,24 +31,18 @@ import org.pegdown.ast.TextNode;
import org.pegdown.plugins.BlockPluginParser;
import org.pegdown.plugins.PegDownPlugins;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Map;
-
-/**
- * Pegdown plugin for YUML.
- */
+/** Pegdown plugin for YUML. */
public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
public PegdownYumlPlugin() {
- super(PegdownParser.OPTIONS,
- PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
- DefaultParseRunnerProvider);
+ super(
+ PegdownParser.OPTIONS, PegdownParser.PARSING_TIMEOUT_AS_MILLIS, DefaultParseRunnerProvider);
}
- public PegdownYumlPlugin(Integer options,
- Long maxParsingTimeInMillis,
- ParseRunnerProvider parseRunnerProvider,
- PegDownPlugins plugins) {
+ public PegdownYumlPlugin(
+ Integer options,
+ Long maxParsingTimeInMillis,
+ ParseRunnerProvider parseRunnerProvider,
+ PegDownPlugins plugins) {
super(options, maxParsingTimeInMillis, parseRunnerProvider, plugins);
}
@@ -77,19 +74,21 @@ public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
startMarker(),
ZeroOrMore(
Sequence(
- parameterName(), name.append(match()),
+ parameterName(),
+ name.append(match()),
String("="),
- OneOrMore(Alphanumeric()), value.append(match())),
+ OneOrMore(Alphanumeric()),
+ value.append(match())),
Sp(),
params.put(name.getString(), value.getString()),
- name.clear(), value.clear()),
+ name.clear(),
+ value.clear()),
body(),
body.append(match()),
endMarker(),
push(
new ExpImageNode(
- "title", createYumlUrl(params.get(), body.getString()), new TextNode("")))
- );
+ "title", createYumlUrl(params.get(), body.getString()), new TextNode(""))));
}
public static String createYumlUrl(Map<String, String> params, String body) {
@@ -137,6 +136,6 @@ public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
@Override
public Rule[] blockPluginRules() {
- return new Rule[]{blockRule()};
+ return new Rule[] {blockRule()};
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/test/java/org/apache/zeppelin/markdown/Markdown4jParserTest.java
----------------------------------------------------------------------
diff --git a/markdown/src/test/java/org/apache/zeppelin/markdown/Markdown4jParserTest.java b/markdown/src/test/java/org/apache/zeppelin/markdown/Markdown4jParserTest.java
index fe381ee..444f42d 100644
--- a/markdown/src/test/java/org/apache/zeppelin/markdown/Markdown4jParserTest.java
+++ b/markdown/src/test/java/org/apache/zeppelin/markdown/Markdown4jParserTest.java
@@ -19,14 +19,12 @@ package org.apache.zeppelin.markdown;
import static org.junit.Assert.assertEquals;
+import java.util.Properties;
+import org.apache.zeppelin.interpreter.InterpreterResult;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
-import org.apache.zeppelin.interpreter.InterpreterResult;
-
public class Markdown4jParserTest {
Markdown md;
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/markdown/src/test/java/org/apache/zeppelin/markdown/PegdownParserTest.java
----------------------------------------------------------------------
diff --git a/markdown/src/test/java/org/apache/zeppelin/markdown/PegdownParserTest.java b/markdown/src/test/java/org/apache/zeppelin/markdown/PegdownParserTest.java
index a608a05..a07c470 100644
--- a/markdown/src/test/java/org/apache/zeppelin/markdown/PegdownParserTest.java
+++ b/markdown/src/test/java/org/apache/zeppelin/markdown/PegdownParserTest.java
@@ -17,11 +17,13 @@
package org.apache.zeppelin.markdown;
+import static org.apache.zeppelin.markdown.PegdownParser.wrapWithMarkdownClassDiv;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.apache.zeppelin.markdown.PegdownParser.wrapWithMarkdownClassDiv;
-
+import java.util.ArrayList;
+import java.util.Properties;
+import org.apache.zeppelin.interpreter.InterpreterResult;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
@@ -31,17 +33,11 @@ import org.junit.rules.ErrorCollector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.Properties;
-
-import org.apache.zeppelin.interpreter.InterpreterResult;
-
public class PegdownParserTest {
Logger logger = LoggerFactory.getLogger(PegdownParserTest.class);
Markdown md;
- @Rule
- public ErrorCollector collector = new ErrorCollector();
+ @Rule public ErrorCollector collector = new ErrorCollector();
@Before
public void setUp() {
@@ -60,18 +56,18 @@ public class PegdownParserTest {
public void testMultipleThread() {
ArrayList<Thread> arrThreads = new ArrayList<>();
for (int i = 0; i < 10; i++) {
- Thread t = new Thread() {
- public void run() {
- String r1 = null;
- try {
- r1 = md.interpret("# H1", null).code().name();
- } catch (Exception e) {
- logger.error("testTestMultipleThread failed to interpret", e);
- }
- collector.checkThat("SUCCESS",
- CoreMatchers.containsString(r1));
- }
- };
+ Thread t =
+ new Thread() {
+ public void run() {
+ String r1 = null;
+ try {
+ r1 = md.interpret("# H1", null).code().name();
+ } catch (Exception e) {
+ logger.error("testTestMultipleThread failed to interpret", e);
+ }
+ collector.checkThat("SUCCESS", CoreMatchers.containsString(r1));
+ }
+ };
t.start();
arrThreads.add(t);
}
@@ -117,7 +113,7 @@ public class PegdownParserTest {
InterpreterResult result = md.interpret("This is ~~deleted~~ text", null);
assertEquals(
wrapWithMarkdownClassDiv("<p>This is <del>deleted</del> text</p>"),
- result.message().get(0).getData());
+ result.message().get(0).getData());
}
@Test
@@ -125,7 +121,7 @@ public class PegdownParserTest {
InterpreterResult result = md.interpret("This is *italics* text", null);
assertEquals(
wrapWithMarkdownClassDiv("<p>This is <em>italics</em> text</p>"),
- result.message().get(0).getData());
+ result.message().get(0).getData());
}
@Test
@@ -186,7 +182,7 @@ public class PegdownParserTest {
.append("\n")
.append(
"[I'm an inline-style link with title](https://www.google.com "
- + "\"Google's Homepage\")\n")
+ + "\"Google's Homepage\")\n")
.append("\n")
.append("[I'm a reference-style link][Arbitrary case-insensitive reference text]\n")
.append("\n")
@@ -213,23 +209,23 @@ public class PegdownParserTest {
"<p><a href=\"https://www.google.com\">I’m an inline-style link</a></p>\n")
.append(
"<p><a href=\"https://www.google.com\" title=\"Google's Homepage\">I’m "
- + "an inline-style link with title</a></p>\n")
+ + "an inline-style link with title</a></p>\n")
.append(
"<p><a href=\"https://www.mozilla.org\">I’m a reference-style link</a></p>\n")
.append(
"<p><a href=\"../blob/master/LICENSE\">I’m a relative reference to a "
- + "repository file</a></p>\n")
+ + "repository file</a></p>\n")
.append(
"<p><a href=\"http://slashdot.org\">You can use numbers for reference-style link "
- + "definitions</a></p>\n")
+ + "definitions</a></p>\n")
.append(
"<p>Or leave it empty and use the <a href=\"http://www.reddit.com\">link text "
- + "itself</a>.</p>\n")
+ + "itself</a>.</p>\n")
.append(
"<p>URLs and URLs in angle brackets will automatically get turned into links."
- + "<br/><a href=\"http://www.example.com\">http://www.example.com</a> or "
- + "<a href=\"http://www.example.com\">http://www.example.com</a> and "
- + "sometimes<br/>example.com (but not on Github, for example).</p>\n")
+ + "<br/><a href=\"http://www.example.com\">http://www.example.com</a> or "
+ + "<a href=\"http://www.example.com\">http://www.example.com</a> and "
+ + "sometimes<br/>example.com (but not on Github, for example).</p>\n")
.append("<p>Some text to show that the reference links can follow later.</p>")
.toString();
@@ -256,26 +252,26 @@ public class PegdownParserTest {
assertEquals(
wrapWithMarkdownClassDiv(
"<blockquote>\n"
- + " <p>Blockquotes are very handy in email to emulate reply text.<br/>This "
- + "line is part of the same quote.</p>\n"
- + "</blockquote>"),
+ + " <p>Blockquotes are very handy in email to emulate reply text.<br/>This "
+ + "line is part of the same quote.</p>\n"
+ + "</blockquote>"),
r1.message().get(0).getData());
InterpreterResult r2 =
md.interpret(
"> This is a very long line that will still be quoted properly when it "
- + "wraps. Oh boy let's keep writing to make sure this is long enough to "
- + "actually wrap for everyone. Oh, you can *put* **MarkdownInterpreter** "
- + "into a blockquote. ",
+ + "wraps. Oh boy let's keep writing to make sure this is long enough to "
+ + "actually wrap for everyone. Oh, you can *put* **MarkdownInterpreter** "
+ + "into a blockquote. ",
null);
assertEquals(
wrapWithMarkdownClassDiv(
"<blockquote>\n"
- + " <p>This is a very long line that will still be quoted properly when "
- + "it wraps. Oh boy let’s keep writing to make sure this is long enough "
- + "to actually wrap for everyone. Oh, you can <em>put</em> "
- + "<strong>MarkdownInterpreter</strong> into a blockquote. </p>\n"
- + "</blockquote>"),
+ + " <p>This is a very long line that will still be quoted properly when "
+ + "it wraps. Oh boy let’s keep writing to make sure this is long enough "
+ + "to actually wrap for everyone. Oh, you can <em>put</em> "
+ + "<strong>MarkdownInterpreter</strong> into a blockquote. </p>\n"
+ + "</blockquote>"),
r2.message().get(0).getData());
}
@@ -379,25 +375,32 @@ public class PegdownParserTest {
// CoreMatchers.containsString("<img src=\"http://www.websequencediagrams.com/?png="));
System.err.println(result.message().get(0).getData());
- if (!result.message().get(0).getData().contains(
- "<img src=\"http://www.websequencediagrams.com/?png=")) {
- logger.error("Expected {} but found {}",
- "<img src=\"http://www.websequencediagrams.com/?png=", result.message().get(0).getData());
+ if (!result
+ .message()
+ .get(0)
+ .getData()
+ .contains("<img src=\"http://www.websequencediagrams.com/?png=")) {
+ logger.error(
+ "Expected {} but found {}",
+ "<img src=\"http://www.websequencediagrams.com/?png=",
+ result.message().get(0).getData());
}
}
@Test
public void testYumlPlugin() {
- String input = new StringBuilder()
- .append("\n \n %%% yuml style=nofunky scale=120 format=svg\n")
- .append("[Customer]<>-orders>[Order]\n")
- .append("[Order]++-0..>[LineItem]\n")
- .append("[Order]-[note:Aggregate root.]\n")
- .append(" %%% ")
- .toString();
+ String input =
+ new StringBuilder()
+ .append("\n \n %%% yuml style=nofunky scale=120 format=svg\n")
+ .append("[Customer]<>-orders>[Order]\n")
+ .append("[Order]++-0..>[LineItem]\n")
+ .append("[Order]-[note:Aggregate root.]\n")
+ .append(" %%% ")
+ .toString();
InterpreterResult result = md.interpret(input, null);
- assertThat(result.message().get(0).getData(),
- CoreMatchers.containsString("<img src=\"http://yuml.me/diagram/"));
+ assertThat(
+ result.message().get(0).getData(),
+ CoreMatchers.containsString("<img src=\"http://yuml.me/diagram/"));
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/neo4j/pom.xml
----------------------------------------------------------------------
diff --git a/neo4j/pom.xml b/neo4j/pom.xml
index 906939c..2bf9e9a 100644
--- a/neo4j/pom.xml
+++ b/neo4j/pom.xml
@@ -138,13 +138,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java
----------------------------------------------------------------------
diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java
index 208d142..2e57570 100644
--- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java
+++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java
@@ -17,17 +17,6 @@
package org.apache.zeppelin.graph.neo4j;
-import org.apache.commons.lang.StringUtils;
-import org.neo4j.driver.v1.AuthToken;
-import org.neo4j.driver.v1.AuthTokens;
-import org.neo4j.driver.v1.Config;
-import org.neo4j.driver.v1.Driver;
-import org.neo4j.driver.v1.GraphDatabase;
-import org.neo4j.driver.v1.Session;
-import org.neo4j.driver.v1.StatementResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -35,17 +24,24 @@ import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
+import org.apache.commons.lang.StringUtils;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.resource.Resource;
import org.apache.zeppelin.resource.ResourcePool;
+import org.neo4j.driver.v1.AuthToken;
+import org.neo4j.driver.v1.AuthTokens;
+import org.neo4j.driver.v1.Config;
+import org.neo4j.driver.v1.Driver;
+import org.neo4j.driver.v1.GraphDatabase;
+import org.neo4j.driver.v1.Session;
+import org.neo4j.driver.v1.StatementResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-/**
- * Neo4j connection manager for Zeppelin.
- */
+/** Neo4j connection manager for Zeppelin. */
public class Neo4jConnectionManager {
static final Logger LOGGER = LoggerFactory.getLogger(Neo4jConnectionManager.class);
-
+
public static final String NEO4J_SERVER_URL = "neo4j.url";
public static final String NEO4J_AUTH_TYPE = "neo4j.auth.type";
public static final String NEO4J_AUTH_USER = "neo4j.auth.user";
@@ -66,16 +62,18 @@ public class Neo4jConnectionManager {
private final AuthToken authToken;
- /**
- * Enum type for the AuthToken.
- */
- public enum Neo4jAuthType {NONE, BASIC}
+ /** Enum type for the AuthToken. */
+ public enum Neo4jAuthType {
+ NONE,
+ BASIC
+ }
public Neo4jConnectionManager(Properties properties) {
this.neo4jUrl = properties.getProperty(NEO4J_SERVER_URL);
- this.config = Config.build()
- .withMaxIdleSessions(Integer.parseInt(properties.getProperty(NEO4J_MAX_CONCURRENCY)))
- .toConfig();
+ this.config =
+ Config.build()
+ .withMaxIdleSessions(Integer.parseInt(properties.getProperty(NEO4J_MAX_CONCURRENCY)))
+ .toConfig();
String authType = properties.getProperty(NEO4J_AUTH_TYPE);
switch (Neo4jAuthType.valueOf(authType.toUpperCase())) {
case BASIC:
@@ -111,8 +109,7 @@ public class Neo4jConnectionManager {
return getDriver().session();
}
- public StatementResult execute(String cypherQuery,
- InterpreterContext interpreterContext) {
+ public StatementResult execute(String cypherQuery, InterpreterContext interpreterContext) {
Map<String, Object> params = new HashMap<>();
if (interpreterContext != null) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
@@ -128,8 +125,8 @@ public class Neo4jConnectionManager {
LOGGER.debug("Executing cypher query {} with params {}", cypherQuery, params);
StatementResult result;
try (Session session = getSession()) {
- result = params.isEmpty()
- ? getSession().run(cypherQuery) : getSession().run(cypherQuery, params);
+ result =
+ params.isEmpty() ? getSession().run(cypherQuery) : getSession().run(cypherQuery, params);
}
return result;
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java
----------------------------------------------------------------------
diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java
index bcb9d7b..6999b5f 100644
--- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java
+++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java
@@ -17,17 +17,7 @@
package org.apache.zeppelin.graph.neo4j;
-import org.apache.commons.lang.StringUtils;
-import org.neo4j.driver.internal.types.InternalTypeSystem;
-import org.neo4j.driver.internal.util.Iterables;
-import org.neo4j.driver.v1.Record;
-import org.neo4j.driver.v1.StatementResult;
-import org.neo4j.driver.v1.Value;
-import org.neo4j.driver.v1.types.Node;
-import org.neo4j.driver.v1.types.Relationship;
-import org.neo4j.driver.v1.types.TypeSystem;
-import org.neo4j.driver.v1.util.Pair;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -37,9 +27,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
+import org.apache.commons.lang.StringUtils;
import org.apache.zeppelin.graph.neo4j.utils.Neo4jConversionUtils;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
@@ -48,10 +36,17 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.graph.GraphResult;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;
+import org.neo4j.driver.internal.types.InternalTypeSystem;
+import org.neo4j.driver.internal.util.Iterables;
+import org.neo4j.driver.v1.Record;
+import org.neo4j.driver.v1.StatementResult;
+import org.neo4j.driver.v1.Value;
+import org.neo4j.driver.v1.types.Node;
+import org.neo4j.driver.v1.types.Relationship;
+import org.neo4j.driver.v1.types.TypeSystem;
+import org.neo4j.driver.v1.util.Pair;
-/**
- * Neo4j interpreter for Zeppelin.
- */
+/** Neo4j interpreter for Zeppelin. */
public class Neo4jCypherInterpreter extends Interpreter {
private static final String TABLE = "%table";
public static final String NEW_LINE = "\n";
@@ -62,9 +57,9 @@ public class Neo4jCypherInterpreter extends Interpreter {
private Map<String, String> labels;
private Set<String> types;
-
+
private final Neo4jConnectionManager neo4jConnectionManager;
-
+
private final ObjectMapper jsonMapper = new ObjectMapper();
public Neo4jCypherInterpreter(Properties properties) {
@@ -84,8 +79,8 @@ public class Neo4jCypherInterpreter extends Interpreter {
public Map<String, String> getLabels(boolean refresh) {
if (labels == null || refresh) {
- Map<String, String> old = labels == null ?
- new LinkedHashMap<String, String>() : new LinkedHashMap<>(labels);
+ Map<String, String> old =
+ labels == null ? new LinkedHashMap<String, String>() : new LinkedHashMap<>(labels);
labels = new LinkedHashMap<>();
StatementResult result = this.neo4jConnectionManager.execute("CALL db.labels()");
Set<String> colors = new HashSet<>();
@@ -122,8 +117,7 @@ public class Neo4jCypherInterpreter extends Interpreter {
return new InterpreterResult(Code.SUCCESS);
}
try {
- StatementResult result = this.neo4jConnectionManager.execute(cypherQuery,
- interpreterContext);
+ StatementResult result = this.neo4jConnectionManager.execute(cypherQuery, interpreterContext);
Set<Node> nodes = new HashSet<>();
Set<Relationship> relationships = new HashSet<>();
List<String> columns = new ArrayList<>();
@@ -141,8 +135,8 @@ public class Neo4jCypherInterpreter extends Interpreter {
nodes.addAll(Iterables.asList(field.value().asPath().nodes()));
relationships.addAll(Iterables.asList(field.value().asPath().relationships()));
} else {
- setTabularResult(field.key(), field.value(), columns, line,
- InternalTypeSystem.TYPE_SYSTEM);
+ setTabularResult(
+ field.key(), field.value(), columns, line, InternalTypeSystem.TYPE_SYSTEM);
}
}
if (!line.isEmpty()) {
@@ -160,15 +154,19 @@ public class Neo4jCypherInterpreter extends Interpreter {
}
}
- private void setTabularResult(String key, Object obj, List<String> columns, List<String> line,
- TypeSystem typeSystem) {
+ private void setTabularResult(
+ String key, Object obj, List<String> columns, List<String> line, TypeSystem typeSystem) {
if (obj instanceof Value) {
Value value = (Value) obj;
if (value.hasType(typeSystem.MAP())) {
Map<String, Object> map = value.asMap();
for (Entry<String, Object> entry : map.entrySet()) {
- setTabularResult(String.format(MAP_KEY_TEMPLATE, key, entry.getKey()), entry.getValue(),
- columns, line, typeSystem);
+ setTabularResult(
+ String.format(MAP_KEY_TEMPLATE, key, entry.getKey()),
+ entry.getValue(),
+ columns,
+ line,
+ typeSystem);
}
} else {
addValueToLine(key, columns, line, value);
@@ -176,8 +174,12 @@ public class Neo4jCypherInterpreter extends Interpreter {
} else if (obj instanceof Map) {
Map<String, Object> map = (Map<String, Object>) obj;
for (Entry<String, Object> entry : map.entrySet()) {
- setTabularResult(String.format(MAP_KEY_TEMPLATE, key, entry.getKey()), entry.getValue(),
- columns, line, typeSystem);
+ setTabularResult(
+ String.format(MAP_KEY_TEMPLATE, key, entry.getKey()),
+ entry.getValue(),
+ columns,
+ line,
+ typeSystem);
}
} else {
addValueToLine(key, columns, line, obj);
@@ -237,8 +239,7 @@ public class Neo4jCypherInterpreter extends Interpreter {
return new InterpreterResult(Code.SUCCESS, msg.toString());
}
- private InterpreterResult renderGraph(Set<Node> nodes,
- Set<Relationship> relationships) {
+ private InterpreterResult renderGraph(Set<Node> nodes, Set<Relationship> relationships) {
logger.info("Executing renderGraph method");
List<org.apache.zeppelin.tabledata.Node> nodesList = new ArrayList<>();
List<org.apache.zeppelin.tabledata.Relationship> relsList = new ArrayList<>();
@@ -249,14 +250,15 @@ public class Neo4jCypherInterpreter extends Interpreter {
for (Node node : nodes) {
nodesList.add(Neo4jConversionUtils.toZeppelinNode(node, labels));
}
- return new GraphResult(Code.SUCCESS,
- new GraphResult.Graph(nodesList, relsList, labels, getTypes(true), true));
+ return new GraphResult(
+ Code.SUCCESS, new GraphResult.Graph(nodesList, relsList, labels, getTypes(true), true));
}
@Override
public Scheduler getScheduler() {
return SchedulerFactory.singleton()
- .createOrGetParallelScheduler(Neo4jCypherInterpreter.class.getName() + this.hashCode(),
+ .createOrGetParallelScheduler(
+ Neo4jCypherInterpreter.class.getName() + this.hashCode(),
Integer.parseInt(getProperty(Neo4jConnectionManager.NEO4J_MAX_CONCURRENCY)));
}
@@ -271,6 +273,5 @@ public class Neo4jCypherInterpreter extends Interpreter {
}
@Override
- public void cancel(InterpreterContext context) {
- }
+ public void cancel(InterpreterContext context) {}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java
----------------------------------------------------------------------
diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java
index 571afa9..ddbc283 100644
--- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java
+++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java
@@ -17,25 +17,22 @@
package org.apache.zeppelin.graph.neo4j.utils;
-import org.neo4j.driver.v1.types.Node;
-import org.neo4j.driver.v1.types.Relationship;
-
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import org.neo4j.driver.v1.types.Node;
+import org.neo4j.driver.v1.types.Relationship;
-/**
- * Neo4jConversionUtils.
- */
+/** Neo4jConversionUtils. */
public class Neo4jConversionUtils {
private Neo4jConversionUtils() {}
-
+
private static final String[] LETTERS = "0123456789ABCDEF".split("");
public static final String COLOR_GREY = "#D3D3D3";
-
- public static org.apache.zeppelin.tabledata.Node toZeppelinNode(Node n,
- Map<String, String> graphLabels) {
+
+ public static org.apache.zeppelin.tabledata.Node toZeppelinNode(
+ Node n, Map<String, String> graphLabels) {
Set<String> labels = new LinkedHashSet<>();
String firstLabel = null;
for (String label : n.labels()) {
@@ -44,13 +41,12 @@ public class Neo4jConversionUtils {
}
labels.add(label);
}
- return new org.apache.zeppelin.tabledata.Node(n.id(), n.asMap(),
- labels);
+ return new org.apache.zeppelin.tabledata.Node(n.id(), n.asMap(), labels);
}
-
+
public static org.apache.zeppelin.tabledata.Relationship toZeppelinRelationship(Relationship r) {
- return new org.apache.zeppelin.tabledata.Relationship(r.id(), r.asMap(),
- r.startNodeId(), r.endNodeId(), r.type());
+ return new org.apache.zeppelin.tabledata.Relationship(
+ r.id(), r.asMap(), r.startNodeId(), r.endNodeId(), r.type());
}
public static String getRandomLabelColor() {