Skip to content

解释员执行Hook(实验)

原文链接 : http://zeppelin.apache.org/docs/0.7.2/manual/interpreterexechooks.html

译文链接 : https://www.apachecn.org/pages/viewpage.action?pageId=10030757

贡献者 : 片刻 ApacheCN Apache中文网

概述

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中手动重新启动解释器组。


我们一直在努力

apachecn/AiLearning

【布客】中文翻译组