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 { + + 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/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,8 @@ 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.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; @@ -773,10 +775,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)); + if (peh instanceof ExecuteWithHookContext) { + ((ExecuteWithHookContext) peh).run(hookContext); + } else { + peh.run(SessionState.get(), plan.getInputs(), plan.getOutputs(), ShimLoader + .getHadoopShims().getUGIForConf(conf)); + } } int jobs = Utilities.getMRTasks(plan.getRootTasks()).size(); @@ -820,6 +827,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) { @@ -886,9 +894,13 @@ // 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)); + if (peh instanceof ExecuteWithHookContext) { + ((ExecuteWithHookContext) peh).run(hookContext); + } else { + peh.run(SessionState.get(), plan.getInputs(), plan.getOutputs(), + (SessionState.get() != null ? SessionState.get().getLineageState().getLineageInfo() + : null), ShimLoader.getHadoopShims().getUGIForConf(conf)); + } } if (SessionState.get() != null) {