use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.
the class FlinkExample method main.
public static void main(String[] args) {
ZSession session = null;
try {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
Map<String, String> intpProperties = new HashMap<>();
session = ZSession.builder().setClientConfig(clientConfig).setInterpreter("flink").setIntpProperties(intpProperties).build();
session.start();
System.out.println("Flink Web UI: " + session.getWeburl());
// scala (single result)
ExecuteResult result = session.execute("benv.fromElements(1,2,3).print()");
System.out.println("Result: " + result.getResults().get(0).getData());
// scala (multiple result)
result = session.execute("val data = benv.fromElements(1,2,3).map(e=>(e, e * 2))\n" + "data.print()\n" + "z.show(data)");
// The first result is text output
System.out.println("Result 1: type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// The second result is table output
System.out.println("Result 2: type: " + result.getResults().get(1).getType() + ", data: " + result.getResults().get(1).getData());
System.out.println("Flink Job Urls:\n" + StringUtils.join(result.getJobUrls(), "\n"));
// error output
result = session.execute("1/0");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
// pyflink
result = session.execute("pyflink", "type(b_env)");
System.out.println("benv: " + result.getResults().get(0).getData());
// matplotlib
result = session.execute("ipyflink", "%matplotlib inline\n" + "import matplotlib.pyplot as plt\n" + "plt.plot([1,2,3,4])\n" + "plt.ylabel('some numbers')\n" + "plt.show()");
System.out.println("Matplotlib result, type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// flink sql
result = session.execute("ssql", "show tables");
System.out.println("Flink tables: " + result.getResults().get(0).getData());
// flink invalid sql
result = session.execute("bsql", "select * from unknown_table");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.
the class PrestoExample method main.
public static void main(String[] args) {
ZSession session = null;
try {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
Map<String, String> intpProperties = new HashMap<>();
session = ZSession.builder().setClientConfig(clientConfig).setInterpreter("presto").setIntpProperties(intpProperties).build();
session.start(new SimpleMessageHandler());
// single sql
ExecuteResult result = session.execute("show schemas");
System.out.println("show schemas result : " + result.getResults().get(0).getData());
// multiple sql
result = session.execute("use tpch_text_5;\nshow tables");
System.out.println("show tables result: " + result.getResults().get(0).getData());
// select
result = session.execute("select count(1) from lineitem");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
// invalid sql
result = session.execute("select * from unknown_table");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.
the class SparkExample method main.
public static void main(String[] args) {
ZSession session = null;
try {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
Map<String, String> intpProperties = new HashMap<>();
intpProperties.put("spark.master", "local[*]");
session = ZSession.builder().setClientConfig(clientConfig).setInterpreter("spark").setIntpProperties(intpProperties).build();
session.start();
System.out.println("Spark Web UI: " + session.getWeburl());
// scala (single result)
ExecuteResult result = session.execute("println(sc.version)");
System.out.println("Spark Version: " + result.getResults().get(0).getData());
// scala (multiple result)
result = session.execute("println(sc.version)\n" + "val df = spark.createDataFrame(Seq((1,\"a\"), (2,\"b\")))\n" + "z.show(df)");
// The first result is text output
System.out.println("Result 1: type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// The second result is table output
System.out.println("Result 2: type: " + result.getResults().get(1).getType() + ", data: " + result.getResults().get(1).getData());
System.out.println("Spark Job Urls:\n" + StringUtils.join(result.getJobUrls(), "\n"));
// error output
result = session.execute("1/0");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
// pyspark
result = session.execute("pyspark", "df = spark.createDataFrame([(1,'a'),(2,'b')])\n" + "df.registerTempTable('df')\n" + "df.show()");
System.out.println("PySpark dataframe: " + result.getResults().get(0).getData());
// matplotlib
result = session.execute("ipyspark", "%matplotlib inline\n" + "import matplotlib.pyplot as plt\n" + "plt.plot([1,2,3,4])\n" + "plt.ylabel('some numbers')\n" + "plt.show()");
System.out.println("Matplotlib result, type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// sparkr
result = session.execute("r", "df <- as.DataFrame(faithful)\nhead(df)");
System.out.println("Sparkr dataframe: " + result.getResults().get(0).getData());
// spark sql
result = session.execute("sql", "select * from df");
System.out.println("Spark Sql dataframe: " + result.getResults().get(0).getData());
// spark invalid sql
result = session.execute("sql", "select * from unknown_table");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.
the class ZeppelinClientIntegrationTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium");
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS.getVarName(), "*");
AbstractTestRestApi.startUp(ZeppelinClientIntegrationTest.class.getSimpleName());
notebook = TestUtils.getInstance(Notebook.class);
clientConfig = new ClientConfig("http://localhost:8080");
zeppelinClient = new ZeppelinClient(clientConfig);
}
use of org.apache.zeppelin.client.ClientConfig in project zeppelin by apache.
the class RExample method main.
public static void main(String[] args) {
ZSession session = null;
try {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
Map<String, String> intpProperties = new HashMap<>();
session = ZSession.builder().setClientConfig(clientConfig).setInterpreter("r").setIntpProperties(intpProperties).build();
session.start(new SimpleMessageHandler());
// single statement
ExecuteResult result = session.execute("bare <- c(1, 2.5, 4)\n" + "print(bare)");
System.out.println(result.getResults().get(0).getData());
// error output
result = session.execute("1/0");
System.out.println("Result status: " + result.getStatus() + ", data: " + result.getResults().get(0).getData());
// R plotting
result = session.execute("ir", "pairs(iris)");
System.out.println("R plotting result, type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// ggplot2
result = session.execute("ir", "library(ggplot2)\n" + "ggplot(mpg, aes(displ, hwy, colour = class)) + \n" + " geom_point()");
System.out.println("ggplot2 plotting result, type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
// googlevis
result = session.execute("ir", "library(googleVis)\n" + "df=data.frame(country=c(\"US\", \"GB\", \"BR\"), \n" + " val1=c(10,13,14), \n" + " val2=c(23,12,32))\n" + "Bar <- gvisBarChart(df)\n" + "print(Bar, tag = 'chart')");
System.out.println("googlevis plotting result, type: " + result.getResults().get(0).getType() + ", data: " + result.getResults().get(0).getData());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Aggregations