Hive在程序启动不同阶段设置了hook供用户自定义不同的行为
一共有四个阶段提供Hook以供注入定制化代码
- Driver run hooks (Pre/Post)
- Semantic analyizer hooks (Pre/Post)
- Execution hooks (Pre/Failure/Post)
- Client statistics publisher
- Driver.run() takes the command
HiveDriverRunHook.preDriverRun()
(HiveConf.ConfVars.HIVE_DRIVER_RUN_HOOKS
)- Driver.compile() starts processing the command: creates the abstract syntax tree
AbstractSemanticAnalyzerHook.preAnalyze()
(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK
)- Semantic analysis
AbstractSemanticAnalyzerHook.postAnalyze()
(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK
)- Create and validate the query plan (physical plan)
- Driver.execute() : ready to run the jobs
ExecuteWithHookContext.run()
(HiveConf.ConfVars.PREEXECHOOKS
)- ExecDriver.execute() runs all the jobs
- For each job at every HiveConf.ConfVars.HIVECOUNTERSPULLINTERVAL interval:
ClientStatsPublisher.run()
is called to publish statistics
(HiveConf.ConfVars.CLIENTSTATSPUBLISHERS
)
If a task fails:ExecuteWithHookContext.run()
(HiveConf.ConfVars.ONFAILUREHOOKS
) - Finish all the tasks
ExecuteWithHookContext.run()
(HiveConf.ConfVars.POSTEXECHOOKS
)- Before returning the result
HiveDriverRunHook.postDriverRun()
(HiveConf.ConfVars.HIVE_DRIVER_RUN_HOOKS
) - Return the result.
For each of the hooks I indicated the interfaces you have to implement. In the brackets there's the corresponding conf. prop. key you have to set in order to register the class at the beginning of the script. E.g: setting the PreExecution hook (9th stage of the workflow)
HiveConf.ConfVars.PREEXECHOOKS -> hive.exec.pre.hooks :
set hive.exec.pre.hooks=com.example.MyPreHook;
Unfortunately these features aren't really documented, but you can always look into the Driver class to see the evaluation order of the hooks.
Remark: I assumed here Hive 0.11.0, I don't think that the Cloudera distribution differs (too much
参考:
http://stackoverflow.com/questions/17461932/hive-execution-hook