run(String) separated the process into two steps. First is compile, second is run.
@Override
public CommandProcessorResponse run(String command) {
CommandProcessorResponse r0 = compileAndRespond(command);
if (r0.getResponseCode() != 0) {
return r0;
}
return run();
}
ReExecDriver#run()
Run compiled statement with retry.
@Override
public CommandProcessorResponse run() {
executionIndex = 0;
int maxExecutuions = 1 + coreDriver.getConf().getIntVar(ConfVars.HIVE_QUERY_MAX_REEXECUTION_COUNT);
while (true) {
executionIndex++;
for (IReExecutionPlugin p : plugins) {
p.beforeExecute(executionIndex, explainReOptimization);
}
coreDriver.getContext().setExecutionIndex(executionIndex);
LOG.info("Execution #{} of query", executionIndex);
CommandProcessorResponse cpr = coreDriver.run();
PlanMapper oldPlanMapper = coreDriver.getPlanMapper();
afterExecute(oldPlanMapper, cpr.getResponseCode() == 0);
boolean shouldReExecute = explainReOptimization && executionIndex==1;
shouldReExecute |= cpr.getResponseCode() != 0 && shouldReExecute();
if (executionIndex >= maxExecutuions || !shouldReExecute) {
return cpr;
}
LOG.info("Preparing to re-execute query");
prepareToReExecute();
CommandProcessorResponse compile_resp = coreDriver.compileAndRespond(currentQuery);
if (compile_resp.failed()) {
LOG.error("Recompilation of the query failed; this is unexpected.");
// FIXME: somehow place pointers that re-execution compilation have failed; the query have been successfully compiled before?
return compile_resp;
}
PlanMapper newPlanMapper = coreDriver.getPlanMapper();
if (!explainReOptimization && !shouldReExecuteAfterCompile(oldPlanMapper, newPlanMapper)) {
LOG.info("re-running the query would probably not yield better results; returning with last error");
// FIXME: retain old error; or create a new one?
return cpr;
}
}
}



