void runCompactionQueries(HiveConf conf, String tmpTableName, CompactionInfo compactionInfo, List<Path> resultDirs,
      List<String> createQueries, List<String> compactionQueries, List<String> dropQueries,
      Map<String, String> tblProperties) throws IOException {
    SessionState sessionState = setupQueryCompactionSession(conf, compactionInfo, tblProperties);
    try {
      for (String query : createQueries) {
        try {
          LOG.info("Running {} compaction query into temp table with query: {}", compactionInfo.type, query);
          DriverUtils.runOnDriver(conf, sessionState, query);
        } catch (Exception ex) {
          Throwable cause = ex;
          while (cause != null && !(cause instanceof AlreadyExistsException)) {
            cause = cause.getCause();
          }
          if (cause == null) {
            throw new IOException(ex);
          }
        }
      }
      for (String query : compactionQueries) {
        LOG.info("Running {} compaction via query: {}", compactionInfo.type, query);
        if (CompactionType.MINOR.equals(compactionInfo.type)) {
          // There was an issue with the query-based MINOR compaction (HIVE-23763), that the row distribution between the FileSinkOperators
          // was not correlated correctly with the bucket numbers. So we could end up with files containing rows from
          // multiple buckets or rows from the same bucket could end up in different FileSinkOperator. This behaviour resulted
          // corrupted files. To fix this, the FileSinkOperator has been extended to be able to handle rows from different buckets.
          // But we also had to be sure that all rows from the same bucket would end up in the same FileSinkOperator. Therefore
          // the ReduceSinkOperator has also been extended to distribute the rows by bucket numbers. To use this logic,
          // these two optimisations have to be turned off for the MINOR compaction. The MAJOR compaction works differently
          // and its query doesn't use reducers, so these optimisations should not be turned off for MAJOR compaction.
          conf.set("hive.optimize.bucketingsorting", "false");
          conf.set("hive.vectorized.execution.enabled", "false");
        }
        DriverUtils.runOnDriver(conf, sessionState, query);
      }
      commitCompaction(tmpTableName, conf);
    } catch (HiveException e) {
      LOG.error("Error doing query based {} compaction", compactionInfo.type, e);
      removeResultDirs(resultDirs, conf);
      throw new IOException(e);
    } finally {
      try {
        for (String query : dropQueries) {
          LOG.info("Running {} compaction query into temp table with query: {}", compactionInfo.type, query);
          DriverUtils.runOnDriver(conf, sessionState, query);
        }
      } catch (HiveException e) {
        LOG.error("Unable to drop temp table {} which was created for running {} compaction", tmpTableName,
            compactionInfo.type);
        LOG.error(ExceptionUtils.getStackTrace(e));
      } finally {
        //restore sessionState
        sessionState.setCompaction(false);
      }
    }
  }
Run all the queries which performs the compaction.
@param conf hive configuration, must be not null.
@param tmpTableName The name of the temporary table.
@param storageDescriptor this is the resolved storage descriptor.
@param writeIds valid write IDs used to filter rows while they're being read for compaction.
@param compactionInfo provides info about the type of compaction.
@param resultDirs the delta/base directory that is created as the result of compaction.
@param createQueries collection of queries which creates the temporary tables.
@param compactionQueries collection of queries which uses data from the original table and writes in temporary
                         tables.
@param dropQueries queries which drops the temporary tables.
@throws IOException error during the run of the compaction.
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/QueryCompactor.java