SessionState.get().getHiveHistory().startQuery(queryStr, conf.getVar(HiveConf.ConfVars.HIVEQUERYID) );
SessionState.get().getHiveHistory().logPlanProgress(plan);
}
resStream = null;
BaseSemanticAnalyzer sem = plan.getPlan();
// Get all the pre execution hooks and execute them.
for(PreExecute peh: getPreExecHooks()) {
peh.run(SessionState.get(),
sem.getInputs(), sem.getOutputs(),
UnixUserGroupInformation.readFromConf(conf, UnixUserGroupInformation.UGI_PROPERTY_NAME));
}
int jobs = countJobs(sem.getRootTasks());
if (jobs > 0) {
console.printInfo("Total MapReduce jobs = " + jobs);
}
if (SessionState.get() != null){
SessionState.get().getHiveHistory().setQueryProperty(queryId,
Keys.QUERY_NUM_TASKS, String.valueOf(jobs));
SessionState.get().getHiveHistory().setIdToTableMap(sem.getIdToTableNameMap());
}
String jobname = Utilities.abbreviate(queryStr, maxlen - 6);
// A runtime that launches runnable tasks as separate Threads through TaskRunners
// As soon as a task isRunnable, it is put in a queue
// At any time, at most maxthreads tasks can be running
// The main thread polls the TaskRunners to check if they have finished.
Queue<Task<? extends Serializable>> runnable = new LinkedList<Task<? extends Serializable>>();
Map<TaskResult, TaskRunner> running = new HashMap<TaskResult, TaskRunner> ();
//Add root Tasks to runnable
for (Task<? extends Serializable> tsk : sem.getRootTasks()) {
addToRunnable(runnable,tsk);
}
// Loop while you either have tasks running, or tasks queued up
while (running.size() != 0 || runnable.peek()!=null) {
// Launch upto maxthreads tasks
while(runnable.peek() != null && running.size() < maxthreads) {
Task<? extends Serializable> tsk = runnable.remove();
curJobNo = launchTask(tsk, queryId, noName,running, jobname, jobs, curJobNo);
}
// poll the Tasks to see which one completed
TaskResult tskRes = pollTasks(running.keySet());
TaskRunner tskRun = running.remove(tskRes);
Task<? extends Serializable> tsk = tskRun.getTask();
int exitVal = tskRes.getExitVal();
if(exitVal != 0) {
//TODO: This error messaging is not very informative. Fix that.
errorMessage = "FAILED: Execution Error, return code " + exitVal
+ " from " + tsk.getClass().getName();
SQLState = "08S01";
console.printError(errorMessage);
if(running.size() !=0) {
taskCleanup();
}
return 9;
}
if (SessionState.get() != null) {
SessionState.get().getHiveHistory().setTaskProperty(queryId,
tsk.getId(), Keys.TASK_RET_CODE, String.valueOf(exitVal));
SessionState.get().getHiveHistory().endTask(queryId, tsk);
}
if (tsk.getChildTasks() != null) {
for (Task<? extends Serializable> child : tsk.getChildTasks()) {
if(isLaunchable(child)) {
addToRunnable(runnable,child);
}
}
}
}
// Get all the post execution hooks and execute them.
for(PostExecute peh: getPostExecHooks()) {
peh.run(SessionState.get(),
sem.getInputs(), sem.getOutputs(),
UnixUserGroupInformation.readFromConf(conf, UnixUserGroupInformation.UGI_PROPERTY_NAME));
}
if (SessionState.get() != null){
SessionState.get().getHiveHistory().setQueryProperty(queryId,