This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 5806756 [ZEPPELIN-4354]. Enhance z.angular for more flexiable data
sharing
5806756 is described below
commit 580675617caeccd71a2f3a7b67cb8b55795a3009
Author: Jeff Zhang <[email protected]>
AuthorDate: Fri Sep 27 14:43:48 2019 +0800
[ZEPPELIN-4354]. Enhance z.angular for more flexiable data sharing
### What is this PR for?
This PR enhance method `z.angular` in `%spark.r` and `%spark.pyspark` so
that angular variables defined in frontend can be shared in backend `%spark`,
`%spark.r`, `%spark.pyspark`
### What type of PR is it?
[ Improvement | Feature ]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-4354
### How should this be tested?
* CI pass
### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Jeff Zhang <[email protected]>
Closes #3464 from zjffdu/ZEPPELIN-4354 and squashes the following commits:
34b11e746 [Jeff Zhang] [ZEPPELIN-4354]. Enhance z.angular for more
flexiable data sharing
---
.../src/main/resources/python/zeppelin_context.py | 6 +++
.../apache/zeppelin/spark/SparkRInterpreter.java | 21 ++++++--
.../src/main/resources/R/zeppelin_sparkr.R | 8 +++
.../zeppelin/display/AngularObjectRegistry.java | 4 +-
.../zeppelin/interpreter/BaseZeppelinContext.java | 59 +++++++++++++++++-----
5 files changed, 77 insertions(+), 21 deletions(-)
diff --git a/python/src/main/resources/python/zeppelin_context.py
b/python/src/main/resources/python/zeppelin_context.py
index dc97c14..e2c0b8c 100644
--- a/python/src/main/resources/python/zeppelin_context.py
+++ b/python/src/main/resources/python/zeppelin_context.py
@@ -61,6 +61,12 @@ class PyZeppelinContext(object):
def get(self, key):
return self.__getitem__(key)
+ def angular(self, key, noteId = None, paragraphId = None):
+ return self.z.angular(key, noteId, paragraphId)
+
+ def angularBind(self, key, value, noteId = None, paragraphId = None):
+ return self.z.angularBind(key, value, noteId, paragraphId)
+
def getInterpreterContext(self):
return self.z.getInterpreterContext()
diff --git
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
index 4afb484..3f76306 100644
---
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
+++
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.spark.SparkContext;
import org.apache.spark.SparkRBackend;
import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.zeppelin.interpreter.AbstractInterpreter;
+import org.apache.zeppelin.interpreter.BaseZeppelinContext;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -44,7 +46,7 @@ import static
org.apache.zeppelin.spark.ZeppelinRDisplay.render;
/**
* R and SparkR interpreter with visualization support.
*/
-public class SparkRInterpreter extends Interpreter {
+public class SparkRInterpreter extends AbstractInterpreter {
private static final Logger logger =
LoggerFactory.getLogger(SparkRInterpreter.class);
private String renderOptions;
@@ -54,7 +56,6 @@ public class SparkRInterpreter extends Interpreter {
private AtomicBoolean rbackendDead = new AtomicBoolean(false);
private SparkContext sc;
private JavaSparkContext jsc;
- private String secret;
public SparkRInterpreter(Properties property) {
super(property);
@@ -120,7 +121,7 @@ public class SparkRInterpreter extends Interpreter {
}
@Override
- public InterpreterResult interpret(String lines, InterpreterContext
interpreterContext)
+ public InterpreterResult internalInterpret(String lines, InterpreterContext
interpreterContext)
throws InterpreterException {
Utils.printDeprecateMessage(sparkInterpreter.getSparkVersion(),
interpreterContext, properties);
@@ -185,8 +186,13 @@ public class SparkRInterpreter extends Interpreter {
@Override
public void close() throws InterpreterException {
- zeppelinR.close();
- this.sparkInterpreter.close();
+ if (this.zeppelinR != null) {
+ zeppelinR.close();
+ }
+ if (this.sparkInterpreter != null) {
+ this.sparkInterpreter.close();
+ this.sparkInterpreter = null;
+ }
}
@Override
@@ -217,6 +223,11 @@ public class SparkRInterpreter extends Interpreter {
}
@Override
+ public BaseZeppelinContext getZeppelinContext() {
+ return sparkInterpreter.getZeppelinContext();
+ }
+
+ @Override
public List<InterpreterCompletion> completion(String buf, int cursor,
InterpreterContext
interpreterContext) {
return new ArrayList<>();
diff --git a/spark/interpreter/src/main/resources/R/zeppelin_sparkr.R
b/spark/interpreter/src/main/resources/R/zeppelin_sparkr.R
index 5f64dfe..f720d56 100644
--- a/spark/interpreter/src/main/resources/R/zeppelin_sparkr.R
+++ b/spark/interpreter/src/main/resources/R/zeppelin_sparkr.R
@@ -66,6 +66,14 @@ z.put <- function(name, object) {
z.get <- function(name) {
SparkR:::callJMethod(.zeppelinContext, "get", name)
}
+z.angular <- function(name, noteId=NULL, paragraphId=NULL) {
+ SparkR:::callJMethod(.zeppelinContext, "angular", name, noteId, paragraphId)
+}
+
+z.angularBind <- function(name, value, noteId=NULL, paragraphId=NULL) {
+ SparkR:::callJMethod(.zeppelinContext, "angularBind", name, value, noteId,
paragraphId)
+}
+
z.input <- function(name, value) {
SparkR:::callJMethod(.zeppelinContext, "input", name, value)
}
diff --git
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java
index 930ed7c..c2e86b6 100644
---
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java
+++
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java
@@ -35,9 +35,7 @@ public class AngularObjectRegistry {
private final String GLOBAL_KEY = "_GLOBAL_";
private AngularObjectRegistryListener listener;
private String interpreterId;
-
-
- AngularObjectListener angularObjectListener;
+ private AngularObjectListener angularObjectListener;
public AngularObjectRegistry(final String interpreterId,
final AngularObjectRegistryListener listener) {
diff --git
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/BaseZeppelinContext.java
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/BaseZeppelinContext.java
index abf2e0a..1b5ead4 100644
---
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/BaseZeppelinContext.java
+++
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/BaseZeppelinContext.java
@@ -407,19 +407,12 @@ public abstract class BaseZeppelinContext {
runNote(context.getNoteId());
}
- private AngularObject getAngularObject(String name, InterpreterContext
interpreterContext) {
+ private AngularObject getAngularObject(String name,
+ String noteId,
+ String paragraphId,
+ InterpreterContext
interpreterContext) {
AngularObjectRegistry registry =
interpreterContext.getAngularObjectRegistry();
- String noteId = interpreterContext.getNoteId();
- // try get local object
- AngularObject paragraphAo = registry.get(name, noteId,
interpreterContext.getParagraphId());
- AngularObject noteAo = registry.get(name, noteId, null);
-
- AngularObject ao = paragraphAo != null ? paragraphAo : noteAo;
-
- if (ao == null) {
- // then global object
- ao = registry.get(name, null, null);
- }
+ AngularObject ao = registry.get(name, noteId, paragraphId);
return ao;
}
@@ -432,7 +425,27 @@ public abstract class BaseZeppelinContext {
*/
@ZeppelinApi
public Object angular(String name) {
- AngularObject ao = getAngularObject(name, interpreterContext);
+ AngularObject ao = getAngularObject(name, interpreterContext.getNoteId(),
+ interpreterContext.getParagraphId(), interpreterContext);
+ if (ao == null) {
+ return null;
+ } else {
+ return ao.get();
+ }
+ }
+
+ public Object angular(String name, String noteId) {
+ AngularObject ao = getAngularObject(name, noteId,
+ interpreterContext.getParagraphId(), interpreterContext);
+ if (ao == null) {
+ return null;
+ } else {
+ return ao.get();
+ }
+ }
+
+ public Object angular(String name, String noteId, String paragraphId) {
+ AngularObject ao = getAngularObject(name, noteId, paragraphId,
interpreterContext);
if (ao == null) {
return null;
} else {
@@ -601,6 +614,7 @@ public abstract class BaseZeppelinContext {
*
* @param name name of the variable
* @param o value
+ * @param noteId
*/
public void angularBind(String name, Object o, String noteId) throws
TException {
AngularObjectRegistry registry =
interpreterContext.getAngularObjectRegistry();
@@ -613,6 +627,25 @@ public abstract class BaseZeppelinContext {
}
/**
+ * Create angular variable in notebook scope and bind with front end Angular
display system.
+ * If variable exists, it'll be overwritten.
+ *
+ * @param name name of the variable
+ * @param o value
+ * @param noteId
+ * @param paragraphId
+ */
+ public void angularBind(String name, Object o, String noteId, String
paragraphId) throws TException {
+ AngularObjectRegistry registry =
interpreterContext.getAngularObjectRegistry();
+
+ if (registry.get(name, noteId, paragraphId) == null) {
+ registry.add(name, o, noteId, paragraphId);
+ } else {
+ registry.get(name, noteId, paragraphId).set(o);
+ }
+ }
+
+ /**
* Create angular variable in notebook scope and bind with front end Angular
display
* system.
* If variable exists, value will be overwritten and watcher will be added.