public static CommandProcessorException createProcessorException(DriverContext driverContext, int ret,
      String errorMessage, String sqlState, Throwable downstreamError) {
    SessionState.getPerfLogger().cleanupPerfLogMetrics();
    driverContext.getQueryDisplay().setErrorMessage(errorMessage);
    if (downstreamError != null && downstreamError instanceof HiveException) {
      ErrorMsg em = ((HiveException)downstreamError).getCanonicalErrorMsg();
      if (em != null) {
        return new CommandProcessorException(ret, em.getErrorCode(), errorMessage, sqlState, downstreamError);
      }
    }
    return new CommandProcessorException(ret, -1, errorMessage, sqlState, downstreamError);
  }
For Query Based compaction to run the query to generate the compacted data.
ql/src/java/org/apache/hadoop/hive/ql/DriverUtils.java