From 2651da39ec1ffc233919e001ee7f8cf413690275 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Thu, 10 Sep 2015 22:07:42 +0200 Subject: [PATCH 01/10] first import --- js/pom.xml | 134 ++++++++++++++++++ .../org/apache/zeppelin/js/JsInterpreter.java | 120 ++++++++++++++++ pom.xml | 3 +- 3 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 js/pom.xml create mode 100644 js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java diff --git a/js/pom.xml b/js/pom.xml new file mode 100644 index 00000000000..690a5ae5c49 --- /dev/null +++ b/js/pom.xml @@ -0,0 +1,134 @@ + + + + + 4.0.0 + + + zeppelin + org.apache.zeppelin + 0.6.0-incubating-SNAPSHOT + .. + + + org.apache.zeppelin + zeppelin-js + jar + 0.6.0-incubating-SNAPSHOT + Zeppelin: Shell interpreter + http://zeppelin.incubator.apache.org + + + + ${project.groupId} + zeppelin-interpreter + ${project.version} + provided + + + + org.apache.commons + commons-exec + 1.1 + + + + org.slf4j + slf4j-api + + + + org.slf4j + slf4j-log4j12 + + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + true + + + + + maven-enforcer-plugin + 1.3.1 + + + enforce + none + + + + + + maven-dependency-plugin + 2.8 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/../../interpreter/sh + false + false + true + runtime + + + + copy-artifact + package + + copy + + + ${project.build.directory}/../../interpreter/sh + false + false + true + runtime + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + + + + + + + + + + diff --git a/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java new file mode 100644 index 00000000000..3bbe231fcc0 --- /dev/null +++ b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.js; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.scheduler.Scheduler; +import org.apache.zeppelin.scheduler.SchedulerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Javascript interpreter for Zeppelin. + * + * @author Leonardo Foderaro + * + * + */ +public class JsInterpreter extends Interpreter { + Logger logger = LoggerFactory.getLogger(JsInterpreter.class); + int commandTimeOut = 600000; + + ScriptEngine engine; + + static { + Interpreter.register("js", JsInterpreter.class.getName()); + } + + public JsInterpreter(Properties property) { + super(property); + + engine = new ScriptEngineManager().getEngineByName("nashorn"); + + } + + @Override + public void open() {} + + @Override + public void close() {} + + + @Override + public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { + logger.info("Run shell command '" + cmd + "'"); + long start = System.currentTimeMillis(); + + StringWriter sw = new StringWriter(); + + String result; + + engine.getContext().setWriter(sw); + + try { + Object o = engine.eval(new StringReader(cmd)); + + if (o != null) { + result = sw.toString() + "\n\r"+ o.toString(); + } else { + result = sw.toString(); + } + + return new InterpreterResult( InterpreterResult.Code.SUCCESS, result.toString()); + } catch (ScriptException e) { + return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage()); + } + + } + + @Override + public void cancel(InterpreterContext context) {} + + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public Scheduler getScheduler() { + return SchedulerFactory.singleton().createOrGetFIFOScheduler( + JsInterpreter.class.getName() + this.hashCode()); + } + + @Override + public List completion(String buf, int cursor) { + return null; + } + +} diff --git a/pom.xml b/pom.xml index 02f161fbc7f..7612ca7e3de 100755 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,7 @@ markdown angular shell + js hive phoenix geode @@ -100,7 +101,7 @@ ignite kylin lens - cassandra + zeppelin-web zeppelin-server zeppelin-distribution From 1b71c693a1e25b998d12404c5caefe073aab9219 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Fri, 11 Sep 2015 23:11:48 +0200 Subject: [PATCH 02/10] fix typo --- js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pom.xml b/js/pom.xml index 690a5ae5c49..3069fd2ebfd 100644 --- a/js/pom.xml +++ b/js/pom.xml @@ -111,7 +111,7 @@ copy - ${project.build.directory}/../../interpreter/sh + ${project.build.directory}/../../interpreter/js false false true From be087d42cd08c8ac46336ecff94f9610a2cb4e57 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Fri, 11 Sep 2015 23:14:45 +0200 Subject: [PATCH 03/10] corrected output directory --- js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pom.xml b/js/pom.xml index 3069fd2ebfd..40018d32487 100644 --- a/js/pom.xml +++ b/js/pom.xml @@ -97,7 +97,7 @@ copy-dependencies - ${project.build.directory}/../../interpreter/sh + ${project.build.directory}/../../interpreter/js false false true From dc6801a096ff1c5f3419a7df99401c0ac8b775fb Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Fri, 11 Sep 2015 23:29:35 +0200 Subject: [PATCH 04/10] fixed Checkstyle violations --- .../org/apache/zeppelin/js/JsInterpreter.java | 109 +++++++++--------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java index 3bbe231fcc0..93898e24680 100644 --- a/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java +++ b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java @@ -43,78 +43,81 @@ * */ public class JsInterpreter extends Interpreter { - Logger logger = LoggerFactory.getLogger(JsInterpreter.class); - int commandTimeOut = 600000; + Logger logger = LoggerFactory.getLogger(JsInterpreter.class); + int commandTimeOut = 600000; - ScriptEngine engine; + ScriptEngine engine; - static { - Interpreter.register("js", JsInterpreter.class.getName()); - } + static { + Interpreter.register("js", JsInterpreter.class.getName()); + } - public JsInterpreter(Properties property) { - super(property); + public JsInterpreter(Properties property) { + super(property); - engine = new ScriptEngineManager().getEngineByName("nashorn"); + engine = new ScriptEngineManager().getEngineByName("nashorn"); - } + } - @Override - public void open() {} + @Override + public void open() { + } - @Override - public void close() {} + @Override + public void close() { + } + @Override + public InterpreterResult interpret(String cmd, + InterpreterContext contextInterpreter) { + logger.info("Run shell command '" + cmd + "'"); + long start = System.currentTimeMillis(); - @Override - public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - logger.info("Run shell command '" + cmd + "'"); - long start = System.currentTimeMillis(); + StringWriter sw = new StringWriter(); - StringWriter sw = new StringWriter(); + String result; - String result; + engine.getContext().setWriter(sw); - engine.getContext().setWriter(sw); + try { + Object o = engine.eval(new StringReader(cmd)); - try { - Object o = engine.eval(new StringReader(cmd)); + if (o != null) { + result = sw.toString() + "\n\r" + o.toString(); + } else { + result = sw.toString(); + } - if (o != null) { - result = sw.toString() + "\n\r"+ o.toString(); - } else { - result = sw.toString(); - } - - return new InterpreterResult( InterpreterResult.Code.SUCCESS, result.toString()); - } catch (ScriptException e) { - return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage()); - } + return new InterpreterResult(InterpreterResult.Code.SUCCESS, result.toString()); + } catch (ScriptException e) { + return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage()); + } - } + } - @Override - public void cancel(InterpreterContext context) {} + @Override + public void cancel(InterpreterContext context) { + } - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } - @Override - public int getProgress(InterpreterContext context) { - return 0; - } + @Override + public int getProgress(InterpreterContext context) { + return 0; + } - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - JsInterpreter.class.getName() + this.hashCode()); - } + @Override + public Scheduler getScheduler() { + return SchedulerFactory.singleton().createOrGetFIFOScheduler( + JsInterpreter.class.getName() + this.hashCode()); + } - @Override - public List completion(String buf, int cursor) { - return null; - } + @Override + public List completion(String buf, int cursor) { + return null; + } } From 1c7778bf2043c68c5e97f54f593fbc8833b77460 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Fri, 11 Sep 2015 23:46:20 +0200 Subject: [PATCH 05/10] fixed typo in log --- js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java index 93898e24680..440892449e6 100644 --- a/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java +++ b/js/src/main/java/org/apache/zeppelin/js/JsInterpreter.java @@ -70,7 +70,7 @@ public void close() { @Override public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - logger.info("Run shell command '" + cmd + "'"); + logger.info("Run js command '" + cmd + "'"); long start = System.currentTimeMillis(); StringWriter sw = new StringWriter(); From eb74343c44bbcbe2ae069227d6cd2564418b32e3 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Sat, 12 Sep 2015 00:12:30 +0200 Subject: [PATCH 06/10] re-enabled Cassandra module --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7612ca7e3de..cbbeef8f660 100755 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ ignite kylin lens - + cassandra zeppelin-web zeppelin-server zeppelin-distribution From 04715b75cc620936f4dc72b9bddaaa572e599497 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Sat, 12 Sep 2015 00:31:16 +0200 Subject: [PATCH 07/10] fixed module name --- js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pom.xml b/js/pom.xml index 40018d32487..23d4bd622b5 100644 --- a/js/pom.xml +++ b/js/pom.xml @@ -30,7 +30,7 @@ zeppelin-js jar 0.6.0-incubating-SNAPSHOT - Zeppelin: Shell interpreter + Zeppelin: JS interpreter http://zeppelin.incubator.apache.org From 31d8a3fd5f83d821c1c682363443bf969c91d832 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Sat, 12 Sep 2015 00:44:57 +0200 Subject: [PATCH 08/10] removed unused dependency --- js/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/js/pom.xml b/js/pom.xml index 23d4bd622b5..31585892aa7 100644 --- a/js/pom.xml +++ b/js/pom.xml @@ -41,12 +41,6 @@ provided - - org.apache.commons - commons-exec - 1.1 - - org.slf4j slf4j-api From a8d8db251879cdd8a035cf4b12b5b5fd47257b87 Mon Sep 17 00:00:00 2001 From: Leonardo Foderaro Date: Fri, 25 Sep 2015 00:58:26 +0200 Subject: [PATCH 09/10] first import --- docs/docs/interpreter/js.md | 159 ++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 docs/docs/interpreter/js.md diff --git a/docs/docs/interpreter/js.md b/docs/docs/interpreter/js.md new file mode 100644 index 00000000000..27173904719 --- /dev/null +++ b/docs/docs/interpreter/js.md @@ -0,0 +1,159 @@ +--- +layout: page +title: "Javascript Interpreter" +description: "" +group: manual +--- + + +## Javascript Interpreter for Apache Zeppelin + +This Interpreter supports the Java 8 "Nashhorn" javascript engine, and it also exposes some Zeppelin components. For example you can iterate over the current Notebook's runners: + + + + + +### Create Interpreter + +By default Zeppelin creates one `PSQL` instance. You can remove it or create new instances. + +Multiple PSQL instances can be created, each configured to the same or different backend databases. But over time a `Notebook` can have only one PSQL interpreter instance `bound`. That means you _can not_ connect to different databases in the same `Notebook`. This is a known Zeppelin limitation. + +To create new PSQL instance open the `Interprter` section and click the `+Create` button. Pick a `Name` of your choice and from the `Interpreter` drop-down select `psql`. Then follow the configuration instructions and `Save` the new instance. + +> Note: The `Name` of the instance is used only to distinct the instances while binding them to the `Notebook`. The `Name` is irrelevant inside the `Notebook`. In the `Notebook` you must use `%psql.sql` tag. + +### Bind to Notebook +In the `Notebook` click on the `settings` icon in the top right corner. The select/deselect the interpreters to be bound with the `Notebook`. + +### Configuration +You can modify the configuration of the PSQL from the `Interpreter` section. The PSQL interpreter expenses the following properties: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property NameDescriptionDefault Value
postgresql.urlJDBC URL to connect to jdbc:postgresql://localhost:5432
postgresql.userJDBC user namegpadmin
postgresql.passwordJDBC password
postgresql.driver.nameJDBC driver name. In this version the driver name is fixed and should not be changedorg.postgresql.Driver
postgresql.max.resultMax number of SQL result to display to prevent the browser overload1000
+ + +### How to use +``` +Tip: Use (CTRL + .) for SQL auto-completion. +``` +#### DDL and SQL commands + +Start the paragraphs with the full `%psql.sql` prefix tag! The short notation: `%psql` would still be able run the queries but the syntax highlighting and the auto-completions will be disabled. + +You can use the standard CREATE / DROP / INSERT commands to create or modify the data model: + +```sql +%psql.sql +drop table if exists mytable; +create table mytable (i int); +insert into mytable select generate_series(1, 100); +``` + +Then in a separate paragraph run the query. + +```sql +%psql.sql +select * from mytable; +``` + +> Note: You can have multiple queries in the same paragraph but only the result from the first is displayed. [[1](https://issues.apache.org/jira/browse/ZEPPELIN-178)], [[2](https://issues.apache.org/jira/browse/ZEPPELIN-212)]. + +For example, this will execute both queries but only the count result will be displayed. If you revert the order of the queries the mytable content will be shown instead. + +```sql +%psql.sql +select count(*) from mytable; +select * from mytable; +``` + +#### PSQL command line tools + +Use the Shell Interpreter (`%sh`) to access the command line [PSQL](http://www.postgresql.org/docs/9.4/static/app-psql.html) interactively: + +```bash +%sh +psql -h phd3.localdomain -U gpadmin -p 5432 < Date: Fri, 25 Sep 2015 00:59:34 +0200 Subject: [PATCH 10/10] added js doc link --- docs/docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/index.md b/docs/docs/index.md index 5fa9c6d19b6..8465e760e25 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -29,6 +29,7 @@ group: nav-right * [tajo](../docs/pleasecontribute.html) * [postgresql, hawq](./interpreter/postgresql.html) * [geode](./interpreter/geode.html) +* [js](../interpreter/js.html) ### Display System