Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void setUp() {
Properties p = new Properties();
flink = new FlinkInterpreter(p);
flink.open();
context = new InterpreterContext(null, null, null, null, null, null, null);
context = new InterpreterContext(null, null, null, null, null, null, null, null);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class IgniteInterpreterTest {
private static final String HOST = "127.0.0.1:47500..47509";

private static final InterpreterContext INTP_CONTEXT =
new InterpreterContext(null, null, null, null, null, null, null);
new InterpreterContext(null, null, null, null, null, null, null, null);

private IgniteInterpreter intp;
private Ignite ignite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class IgniteSqlInterpreterTest {
private static final String HOST = "127.0.0.1:47500..47509";

private static final InterpreterContext INTP_CONTEXT =
new InterpreterContext(null, null, null, null, null, null, null);
new InterpreterContext(null, null, null, null, null, null, null, null);

private Ignite ignite;
private IgniteSqlInterpreter intp;
Expand Down
255 changes: 228 additions & 27 deletions spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,45 +466,232 @@ public List<String> listParagraphs() {
}


private AngularObject getAngularObject(String name, InterpreterContext interpreterContext) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
String noteId = interpreterContext.getNoteId();
// try get local object
AngularObject ao = registry.get(name, interpreterContext.getNoteId());
if (ao == null) {
// then global object
ao = registry.get(name, null);
}
return ao;
}


/**
* Get angular object. Look up local registry first and then global registry
* @param name variable name
* @return value
*/
public Object angular(String name) {
AngularObject ao = getAngularObject(name, interpreterContext);
if (ao == null) {
return null;
} else {
return ao.get();
}
}

/**
* Get angular object. Look up global registry
* @param name variable name
* @return value
*/
public Object angularGlobal(String name) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
AngularObject ao = registry.get(name);
AngularObject ao = registry.get(name, null);
if (ao == null) {
return null;
} else {
return ao.get();
}
}

/**
* Create angular variable in local registry and bind with front end Angular display system.
* If variable exists, it'll be overwritten.
* @param name name of the variable
* @param o value
*/
public void angularBind(String name, Object o) {
angularBind(name, o, interpreterContext.getNoteId());
}

/**
* Create angular variable in global registry and bind with front end Angular display system.
* If variable exists, it'll be overwritten.
* @param name name of the variable
* @param o value
*/
public void angularBindGlobal(String name, Object o) {
angularBind(name, o, (String) null);
}

/**
* Create angular variable in local registry and bind with front end Angular display system.
* If variable exists, value will be overwritten and watcher will be added.
* @param name name of variable
* @param o value
* @param watcher watcher of the variable
*/
public void angularBind(String name, Object o, AngularObjectWatcher watcher) {
angularBind(name, o, interpreterContext.getNoteId(), watcher);
}

/**
* Create angular variable in global registry and bind with front end Angular display system.
* If variable exists, value will be overwritten and watcher will be added.
* @param name name of variable
* @param o value
* @param watcher watcher of the variable
*/
public void angularBindGlobal(String name, Object o, AngularObjectWatcher watcher) {
angularBind(name, o, null, watcher);
}

public void angularBind(String name, Object o) {
/**
* Add watcher into angular variable (local registry)
* @param name name of the variable
* @param watcher watcher
*/
public void angularWatch(String name, AngularObjectWatcher watcher) {
angularWatch(name, interpreterContext.getNoteId(), watcher);
}

/**
* Add watcher into angular variable (global registry)
* @param name name of the variable
* @param watcher watcher
*/
public void angularWatchGlobal(String name, AngularObjectWatcher watcher) {
angularWatch(name, null, watcher);
}


public void angularWatch(String name,
final scala.Function2<Object, Object, Unit> func) {
angularWatch(name, interpreterContext.getNoteId(), func);
}

public void angularWatchGlobal(String name,
final scala.Function2<Object, Object, Unit> func) {
angularWatch(name, null, func);
}

public void angularWatch(
String name,
final scala.Function3<Object, Object, InterpreterContext, Unit> func) {
angularWatch(name, interpreterContext.getNoteId(), func);
}

public void angularWatchGlobal(
String name,
final scala.Function3<Object, Object, InterpreterContext, Unit> func) {
angularWatch(name, null, func);
}

/**
* Remove watcher from angular variable (local)
* @param name
* @param watcher
*/
public void angularUnwatch(String name, AngularObjectWatcher watcher) {
angularUnwatch(name, interpreterContext.getNoteId(), watcher);
}

/**
* Remove watcher from angular variable (global)
* @param name
* @param watcher
*/
public void angularUnwatchGlobal(String name, AngularObjectWatcher watcher) {
angularUnwatch(name, null, watcher);
}


/**
* Remove all watchers for the angular variable (local)
* @param name
*/
public void angularUnwatch(String name) {
angularUnwatch(name, interpreterContext.getNoteId());
}

/**
* Remove all watchers for the angular variable (global)
* @param name
*/
public void angularUnwatchGlobal(String name) {
angularUnwatch(name, (String) null);
}

/**
* Remove angular variable and all the watchers.
* @param name
*/
public void angularUnbind(String name) {
String noteId = interpreterContext.getNoteId();
angularUnbind(name, noteId);
}

/**
* Remove angular variable and all the watchers.
* @param name
*/
public void angularUnbindGlobal(String name) {
angularUnbind(name, null);
}

/**
* Create angular variable in local registry and bind with front end Angular display system.
* If variable exists, it'll be overwritten.
* @param name name of the variable
* @param o value
*/
private void angularBind(String name, Object o, String noteId) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) == null) {
registry.add(name, o);

if (registry.get(name, noteId) == null) {
registry.add(name, o, noteId);
} else {
registry.get(name).set(o);
registry.get(name, noteId).set(o);
}
}

public void angularBind(String name, Object o, AngularObjectWatcher w) {

/**
* Create angular variable in local registry and bind with front end Angular display system.
* If variable exists, value will be overwritten and watcher will be added.
* @param name name of variable
* @param o value
* @param watcher watcher of the variable
*/
private void angularBind(String name, Object o, String noteId, AngularObjectWatcher watcher) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) == null) {
registry.add(name, o);

if (registry.get(name, noteId) == null) {
registry.add(name, o, noteId);
} else {
registry.get(name).set(o);
registry.get(name, noteId).set(o);
}
angularWatch(name, w);
angularWatch(name, watcher);
}

public void angularWatch(String name, AngularObjectWatcher w) {
/**
* Add watcher into angular binding variable
* @param name name of the variable
* @param watcher watcher
*/
private void angularWatch(String name, String noteId, AngularObjectWatcher watcher) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) != null) {
registry.get(name).addWatcher(w);

if (registry.get(name, noteId) != null) {
registry.get(name, noteId).addWatcher(watcher);
}
}


public void angularWatch(String name,
private void angularWatch(String name, String noteId,
final scala.Function2<Object, Object, Unit> func) {
AngularObjectWatcher w = new AngularObjectWatcher(getInterpreterContext()) {
@Override
Expand All @@ -513,11 +700,12 @@ public void watch(Object oldObject, Object newObject,
func.apply(newObject, newObject);
}
};
angularWatch(name, w);
angularWatch(name, noteId, w);
}

public void angularWatch(
private void angularWatch(
String name,
String noteId,
final scala.Function3<Object, Object, InterpreterContext, Unit> func) {
AngularObjectWatcher w = new AngularObjectWatcher(getInterpreterContext()) {
@Override
Expand All @@ -526,25 +714,38 @@ public void watch(Object oldObject, Object newObject,
func.apply(oldObject, newObject, context);
}
};
angularWatch(name, w);
}
angularWatch(name, noteId, w);
}

public void angularUnwatch(String name, AngularObjectWatcher w) {
/**
* Remove watcher
* @param name
* @param watcher
*/
private void angularUnwatch(String name, String noteId, AngularObjectWatcher watcher) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) != null) {
registry.get(name).removeWatcher(w);
if (registry.get(name, noteId) != null) {
registry.get(name, noteId).removeWatcher(watcher);
}
}

public void angularUnwatch(String name) {
/**
* Remove all watchers for the angular variable
* @param name
*/
private void angularUnwatch(String name, String noteId) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
if (registry.get(name) != null) {
registry.get(name).clearAllWatchers();
if (registry.get(name, noteId) != null) {
registry.get(name, noteId).clearAllWatchers();
}
}

public void angularUnbind(String name) {
/**
* Remove angular variable and all the watchers.
* @param name
*/
private void angularUnbind(String name, String noteId) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
registry.remove(name);
registry.remove(name, noteId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setUp() throws Exception {
intpGroup.add(dep);
dep.setInterpreterGroup(intpGroup);

context = new InterpreterContext("id", "title", "text", new HashMap<String, Object>(), new GUI(),
context = new InterpreterContext("note", "id", "title", "text", new HashMap<String, Object>(), new GUI(),
new AngularObjectRegistry(intpGroup.getId(), null),
new LinkedList<InterpreterContextRunner>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void setUp() throws Exception {
}

InterpreterGroup intpGroup = new InterpreterGroup();
context = new InterpreterContext("id", "title", "text",
context = new InterpreterContext("note", "id", "title", "text",
new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(
intpGroup.getId(), null),
new LinkedList<InterpreterContextRunner>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setUp() throws Exception {
sql.setInterpreterGroup(intpGroup);
sql.open();
}
context = new InterpreterContext("id", "title", "text", new HashMap<String, Object>(), new GUI(),
context = new InterpreterContext("note", "id", "title", "text", new HashMap<String, Object>(), new GUI(),
new AngularObjectRegistry(intpGroup.getId(), null),
new LinkedList<InterpreterContextRunner>());
}
Expand Down
Loading