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.