org.apache.hadoop.hive.ql.hooks.HookContext Maven / Gradle / Ivy
/**
* 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 java.util.Map;
import java.util.Set;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.QueryPlan;
import org.apache.hadoop.hive.ql.exec.TaskRunner;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.shims.ShimLoader;
import org.apache.hadoop.security.UserGroupInformation;
/**
* Hook Context keeps all the necessary information for all the hooks.
* New implemented hook can get the query plan, job conf and the list of all completed tasks from this hook context
*/
public class HookContext {
static public enum HookType {
PRE_EXEC_HOOK, POST_EXEC_HOOK, ON_FAILURE_HOOK
}
private QueryPlan queryPlan;
private HiveConf conf;
private List completeTaskList;
private Set inputs;
private Set outputs;
private LineageInfo linfo;
private UserGroupInformation ugi;
private HookType hookType;
final private Map inputPathToContentSummary;
private final String ipAddress;
private final String userName;
public HookContext(QueryPlan queryPlan, HiveConf conf,
Map inputPathToContentSummary, String userName, String ipAddress) throws Exception {
this.queryPlan = queryPlan;
this.conf = conf;
this.inputPathToContentSummary = inputPathToContentSummary;
completeTaskList = new ArrayList();
inputs = queryPlan.getInputs();
outputs = queryPlan.getOutputs();
ugi = ShimLoader.getHadoopShims().getUGIForConf(conf);
linfo= null;
if(SessionState.get() != null){
linfo = SessionState.get().getLineageState().getLineageInfo();
}
this.ipAddress = ipAddress;
this.userName = userName;
}
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);
}
public Set getInputs() {
return inputs;
}
public void setInputs(Set inputs) {
this.inputs = inputs;
}
public Set getOutputs() {
return outputs;
}
public void setOutputs(Set outputs) {
this.outputs = outputs;
}
public LineageInfo getLinfo() {
return linfo;
}
public void setLinfo(LineageInfo linfo) {
this.linfo = linfo;
}
public UserGroupInformation getUgi() {
return ugi;
}
public void setUgi(UserGroupInformation ugi) {
this.ugi = ugi;
}
public Map getInputPathToContentSummary() {
return inputPathToContentSummary;
}
public HookType getHookType() {
return hookType;
}
public void setHookType(HookType hookType) {
this.hookType = hookType;
}
public String getIpAddress() {
return this.ipAddress;
}
public String getOperationName() {
return SessionState.get().getHiveOperation().name();
}
public String getUserName() {
return this.userName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy