# 解釋員執行Hook(實驗)
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/manual/interpreterexechooks.html](http://zeppelin.apache.org/docs/0.7.2/manual/interpreterexechooks.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030757](http://www.apache.wiki/pages/viewpage.action?pageId=10030757)
貢獻者 : [片刻](/display/~jiangzhonglian) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概述
Apache Zeppelin允許用戶在前后段代碼執行時指定由解釋器執行的附加代碼。如果您需要在特定時間為筆記本中的所有段落運行相同的代碼集,這主要是有用的。目前,此功能僅適用于spark和pyspark解釋器。要指定你的Hook代碼,你可以使用`z.registerHook()`。例如,將以下內容輸入到一個段落中:
```
%pyspark
z.registerHook("post_exec", "print 'This code should be executed before the parapgraph code!'")
z.registerHook("pre_exec", "print 'This code should be executed after the paragraph code!'")?
```
這些調用在下一次運行一段時才會生效。
在另一段中,輸入
```
%pyspark
print "This code should be entered into the paragraph by the user!"?
```
輸出應為:
```
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! ?
```
如果你需要知道鉤子代碼,請使用`z.getHook()`:
```
%pyspark
print z.getHook("post_exec")
print 'This code should be executed after the paragraph code!'?
```
任何調用`z.registerHook()`將自動覆蓋以前注冊的內容。要完全注銷掛鉤事件,請使用`z.unregisterHook(eventCode)`。目前只有`"post_exec"`和`"pre_exec"`Zeppelin Hook注冊表系統的有效的事件代碼。
最后,hook注冊表由同一組中的其他解釋器內部共享。這將允許一個解釋器REPL的鉤子代碼由另一個解釋器設置,如下所示:
```
%spark
z.unregisterHook("post_exec", "pyspark")?
```
該API對于spark(scala)和pyspark(python)實現是相同的。
### 注意事項
打電話`z.registerHook("pre_exec", ...)`應小心。如果您指定的鉤子代碼有錯誤,這將導致解釋器REPL無法執行任何代碼通過預執行階段,使得直接調用不可能`z.unregisterHook()`生效。當前的解決方法包括`z.unregisterHook()`通過同一解釋器組(見上文)中的其他解釋器REPL進行調用,或者在UI中手動重新啟動解釋器組。
- 快速入門
- 什么是Apache Zeppelin?
- 安裝
- 配置
- 探索Apache Zeppelin UI
- 教程
- 動態表單
- 發表你的段落
- 自定義Zeppelin主頁
- 升級Zeppelin版本
- 從源碼編譯
- 使用Flink和Spark Clusters安裝Zeppelin教程
- 解釋器
- 概述
- 解釋器安裝
- 解釋器依賴管理
- 解釋器的模擬用戶
- 解釋員執行Hook(實驗)
- Alluxio 解釋器
- Beam 解釋器
- BigQuery 解釋器
- Cassandra CQL 解釋器
- Elasticsearch 解釋器
- Flink 解釋器
- Geode/Gemfire OQL 解釋器
- HBase Shell 解釋器
- HDFS文件系統 解釋器
- Hive 解釋器
- Ignite 解釋器
- JDBC通用 解釋器
- Kylin 解釋器
- Lens 解釋器
- Livy 解釋器
- Markdown 解釋器
- Pig 解釋器
- PostgreSQL, HAWQ 解釋器
- Python 2&3解釋器
- R 解釋器
- Scalding 解釋器
- Scio 解釋器
- Shell 解釋器
- Spark 解釋器
- 系統顯示
- 系統基本顯示
- 后端Angular API
- 前端Angular API
- 更多
- 筆記本存儲
- REST API
- 解釋器 API
- 筆記本 API
- 筆記本資源 API
- 配置 API
- 憑據 API
- Helium API
- Security ( 安全 )
- Shiro 授權
- 筆記本 授權
- 數據源 授權
- Helium 授權
- Advanced ( 高級 )
- Zeppelin on Vagrant VM ( Zeppelin 在 Vagrant 虛擬機上 )
- Zeppelin on Spark Cluster Mode( Spark 集群模式下的 Zeppelin )
- Zeppelin on CDH ( Zeppelin 在 CDH 上 )
- Contibute ( 貢獻 )
- Writing a New Interpreter ( 寫一個新的解釋器 )
- Writing a new Visualization (Experimental) ( 編寫新的可視化(實驗) )
- Writing a new Application (Experimental) ( 寫一個新的應用程序( 實驗 ) )
- Contributing to Apache Zeppelin ( Code ) ( 向 Apache Zeppelin 貢獻( 代碼 ) )
- Contributing to Apache Zeppelin ( Website ) ( 向 Apache Zeppelin 貢獻(website) )