public QueryPlan compile(String rawCommand, boolean deferClose) throws CommandProcessorException {
    initialize(rawCommand);

    Throwable compileException = null;
    boolean parsed = false;
    QueryPlan plan = null;
    try {
      DriverUtils.checkInterrupted(driverState, driverContext, "before parsing and analysing the query", null, null);

      parse();
      parsed = true;
      BaseSemanticAnalyzer sem = analyze();

      DriverUtils.checkInterrupted(driverState, driverContext, "after analyzing query.", null, null);

      plan = createPlan(sem);
      
      if (HiveOperation.START_TRANSACTION == queryState.getHiveOperation()
          || plan.isRequiresOpenTransaction()) {
        openTxnAndGetValidTxnList();
      }
      verifyTxnState();
      
      initializeFetchTask(plan);
      authorize(sem);
      explainOutput(sem, plan);
    } catch (CommandProcessorException cpe) {
      compileException = cpe.getCause();
      throw cpe;
    } catch (Exception e) {
      compileException = e;
      DriverUtils.checkInterrupted(driverState, driverContext, "during query compilation: " + e.getMessage(), null,
          null);
      handleException(e);
    } finally {
      cleanUp(compileException, parsed, deferClose);
    }

    return plan;
  }
@param deferClose indicates if the close/destroy should be deferred when the process has been interrupted
            it should be set to true if the compile method is called within another method like runInternal,
            which defers the close to the called in that method.
ql/src/java/org/apache/hadoop/hive/ql/Compiler.java