Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/Hook.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/Hook.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/Hook.java (revision 0) @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.hooks; + +public interface Hook { + +} Property changes on: ql/src/java/org/apache/hadoop/hive/ql/hooks/Hook.java ___________________________________________________________________ Added: svn:executable + * Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/ExecuteWithHookContext.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/ExecuteWithHookContext.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/ExecuteWithHookContext.java (revision 0) @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.hooks; + + +public interface ExecuteWithHookContext extends Hook { + + void run(HookContext hookContext) throws Exception; + +} Property changes on: ql/src/java/org/apache/hadoop/hive/ql/hooks/ExecuteWithHookContext.java ___________________________________________________________________ Added: svn:executable + * Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/HookContext.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/HookContext.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/HookContext.java (revision 0) @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.hadoop.hive.ql.hooks; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.QueryPlan; +import org.apache.hadoop.hive.ql.exec.TaskRunner; + +public class HookContext { + private QueryPlan queryPlan; + private HiveConf conf; + private List completeTaskList; + + + public HookContext(QueryPlan queryPlan, HiveConf conf) { + this.queryPlan = queryPlan; + this.conf = conf; + completeTaskList = new ArrayList(); + } + + public QueryPlan getQueryPlan() { + return queryPlan; + } + + public void setQueryPlan(QueryPlan queryPlan) { + this.queryPlan = queryPlan; + } + + public HiveConf getConf() { + return conf; + } + + public void setConf(HiveConf conf) { + this.conf = conf; + } + + public List getCompleteTaskList() { + return completeTaskList; + } + + public void setCompleteTaskList(List completeTaskList) { + this.completeTaskList = completeTaskList; + } + + public void addCompleteTask(TaskRunner completeTaskRunner) { + completeTaskList.add(completeTaskRunner); + } + +} Property changes on: ql/src/java/org/apache/hadoop/hive/ql/hooks/HookContext.java ___________________________________________________________________ Added: svn:executable + * Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/PostExecute.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/PostExecute.java (revision 1036137) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/PostExecute.java (working copy) @@ -27,7 +27,7 @@ * The post execute hook interface. A list of such hooks can be configured to be * called after compilation and before execution. */ -public interface PostExecute { +public interface PostExecute extends Hook { /** * The run command that is called just before the execution of the query. Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/PreExecute.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/PreExecute.java (revision 1036137) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/PreExecute.java (working copy) @@ -27,7 +27,7 @@ * The pre execute hook interface. A list of such hooks can be configured to be * called after compilation and before execution. */ -public interface PreExecute { +public interface PreExecute extends Hook { /** * The run command that is called just before the execution of the query. Index: ql/src/java/org/apache/hadoop/hive/ql/Driver.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java (revision 1036137) +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java (working copy) @@ -55,6 +55,9 @@ import org.apache.hadoop.hive.ql.exec.TaskRunner; import org.apache.hadoop.hive.ql.exec.Utilities; import org.apache.hadoop.hive.ql.history.HiveHistory.Keys; +import org.apache.hadoop.hive.ql.hooks.ExecuteWithHookContext; +import org.apache.hadoop.hive.ql.hooks.Hook; +import org.apache.hadoop.hive.ql.hooks.HookContext; import org.apache.hadoop.hive.ql.hooks.PostExecute; import org.apache.hadoop.hive.ql.hooks.PreExecute; import org.apache.hadoop.hive.ql.hooks.ReadEntity; @@ -702,8 +705,8 @@ return new CommandProcessorResponse(ret); } - private List getPreExecHooks() throws Exception { - ArrayList pehooks = new ArrayList(); + private List getPreExecHooks() throws Exception { + ArrayList pehooks = new ArrayList(); String pestr = conf.getVar(HiveConf.ConfVars.PREEXECHOOKS); pestr = pestr.trim(); if (pestr.equals("")) { @@ -725,8 +728,8 @@ return pehooks; } - private List getPostExecHooks() throws Exception { - ArrayList pehooks = new ArrayList(); + private List getPostExecHooks() throws Exception { + ArrayList pehooks = new ArrayList(); String pestr = conf.getVar(HiveConf.ConfVars.POSTEXECHOOKS); pestr = pestr.trim(); if (pestr.equals("")) { @@ -773,10 +776,15 @@ } resStream = null; + HookContext hookContext = new HookContext(plan, conf); // Get all the pre execution hooks and execute them. - for (PreExecute peh : getPreExecHooks()) { - peh.run(SessionState.get(), plan.getInputs(), plan.getOutputs(), ShimLoader - .getHadoopShims().getUGIForConf(conf)); + for (Hook peh : getPreExecHooks()) { + if (peh instanceof ExecuteWithHookContext) { + ((ExecuteWithHookContext) peh).run(hookContext); + } else if (peh instanceof PreExecute) { + ((PreExecute)peh).run(SessionState.get(), plan.getInputs(), plan.getOutputs(), ShimLoader + .getHadoopShims().getUGIForConf(conf)); + } } int jobs = Utilities.getMRTasks(plan.getRootTasks()).size(); @@ -820,6 +828,7 @@ TaskResult tskRes = pollTasks(running.keySet()); TaskRunner tskRun = running.remove(tskRes); Task tsk = tskRun.getTask(); + hookContext.addCompleteTask(tskRun); int exitVal = tskRes.getExitVal(); if (exitVal != 0) { @@ -885,10 +894,14 @@ } // Get all the post execution hooks and execute them. - for (PostExecute peh : getPostExecHooks()) { - peh.run(SessionState.get(), plan.getInputs(), plan.getOutputs(), - (SessionState.get() != null ? SessionState.get().getLineageState().getLineageInfo() - : null), ShimLoader.getHadoopShims().getUGIForConf(conf)); + for (Hook peh : getPostExecHooks()) { + if (peh instanceof ExecuteWithHookContext) { + ((ExecuteWithHookContext) peh).run(hookContext); + } else if (peh instanceof PostExecute) { + ((PostExecute)peh).run(SessionState.get(), plan.getInputs(), plan.getOutputs(), + (SessionState.get() != null ? SessionState.get().getLineageState().getLineageInfo() + : null), ShimLoader.getHadoopShims().getUGIForConf(conf)); + } } if (SessionState.get() != null) {