@Override
  public CommandProcessorResponse compileAndRespond(String statement) throws CommandProcessorException {
    currentQuery = statement;

    checkHookConfig();

    int compileIndex = 0;
    int maxCompilations = 1 + coreDriver.getConf().getIntVar(ConfVars.HIVE_QUERY_MAX_RECOMPILATION_COUNT);
    while (true) {
      compileIndex++;

      final int currentIndex = compileIndex;
      plugins.forEach(p -> p.beforeCompile(currentIndex));

      LOG.info("Compile #{} of query", compileIndex);
      CommandProcessorResponse cpr = null;
      CommandProcessorException cpe = null;
      try {
        cpr = coreDriver.compileAndRespond(statement);
      } catch (CommandProcessorException e) {
        cpe = e;
      }

      final boolean success = cpe == null;
      plugins.forEach(p -> p.afterCompile(success));

      // If the compilation was successful return the result
      if (success) {
        return cpr;
      }

      if (compileIndex >= maxCompilations || !plugins.stream().anyMatch(p -> p.shouldReCompile(currentIndex))) {
        // If we do not have to recompile, return the last error
        throw cpe;
      }

      // Prepare for the recompile and start the next loop
      plugins.forEach(IReExecutionPlugin::prepareToReCompile);
    }
  }
Enables to use re-execution logics.

Covers the IDriver interface, handles query re-execution; and asks clear questions from the underlying re-execution plugins.
ql/src/java/org/apache/hadoop/hive/ql/reexec/ReExecDriver.java