GitHub user agoodm opened a pull request:
https://github.com/apache/zeppelin/pull/1470
ZEPPELIN-1423 - Allow users to specify pre/post-execute hooks for
interpreters
### What is this PR for?
See #1439. This is a second attempt based on prior feedback, particularly
from @Leemoonsoo who advised that it would be better to contain all of the code
inside of the Interpreter Process. Aside from this, the major changes since the
previous PR are:
- The terminology "hooks" is used instead of "callbacks". Since the
information being passed to the interpreter isn't actually a "callback",
strictly speaking, the more general term "hook" is probably a better choice.
All variable / class names were updated correspondingly.
- The registry is now keyed by class name rather than the `replName`
specified by the magic on top of the paragraph. The interface provided by
`ZeppelinContext` allows for a `replName` to be converted to `className`
through an internal mapping.
- Two new event codes, "PRE_EXEC_DEV" and "POST_EXEC_DEV" have been added.
This is primarily intended to separate use cases for the interpreter
maintainers (via subclasses of `Interpreter`) and the notebook users (via the
`ZeppelinContext` class), as otherwise user attempts at registering a hook
would overwrite that set by the interpreter maintainer.
- Global scope for hook registration is supported for the developer use
cases.
### What type of PR is it?
New Feature
### What is the Jira issue?
[ZEPPELIN-1423](https://issues.apache.org/jira/browse/ZEPPELIN-1423)
### How should this be tested?
In a new note, add the following lines of code to a paragraph:
```python
%pyspark
z.registerCallback("post_exec", "print 'This code should be executed before
the parapgraph code!'")
z.registerCallback("pre_exec", "print 'This code should be executed after
the paragraph code!'")
```
Then run any other paragraph in the note containing some other code, eg
```python
%pyspark
print "This code should be entered into the paragraph by the user!"
```
The output should be:
```
This code should be executed before the paragraph code!
This code should be entered into the paragraph by the user!
This code should be executed after the paragraph code!
```
You should also test out the other two methods (`getCallback()` and
`unregisterCallback()`) specified in `ZeppelinContext.java`.
One final caveat that should be mentioned: If there are errors in the code
you specify for a pre-execute event, it will render the interpreter useless
since the current implementation prepends the the code specified in `pre_exec`
directly to the paragraph entered code before calling `interpret()`. The
current workaround for this would be to either restart the interpreter group or
call `unregisterCallback()` via a different REPL within the interpreter group
(eg, `z.unregisterCallback("pre_exec", "pyspark")` from the spark interpreter).
I would appreciate if anyone here would be willing to share any better
approaches here.
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? Yes
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/agoodm/zeppelin ZEPPELIN-1423v2
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/zeppelin/pull/1470.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1470
----
commit 8fad93674420da1faf4d63ed3f4902c630f2ca26
Author: Alex Goodman <[email protected]>
Date: 2016-09-28T19:27:12Z
Added Interpreter Hooks to Interpreter Process
commit 07cac65e99f643971b171756d26e7e8da92b76d3
Author: Alex Goodman <[email protected]>
Date: 2016-09-29T00:28:50Z
Implemented user-defined hook registry system for spark/pyspark interpreters
commit 1331fe1bd3d89394f74d5f7a0543a56911138f0b
Author: Alex Goodman <[email protected]>
Date: 2016-09-29T00:38:49Z
Update interpreters.md
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---