public void loadTable(Path loadPath, String tableName, LoadFileType loadFileType, boolean isSrcLocal,
      boolean isSkewedStoreAsSubdir, boolean isAcidIUDoperation, boolean resetStatistics,
      Long writeId, int stmtId, boolean isInsertOverwrite, boolean isDirectInsert) throws HiveException {

    PerfLogger perfLogger = SessionState.getPerfLogger();
    perfLogger.perfLogBegin("MoveTask", PerfLogger.LOAD_TABLE);

    List<FileStatus> newFiles = null;
    Table tbl = getTable(tableName);
    assert tbl.getPath() != null : "null==getPath() for " + tbl.getTableName();
    boolean isTxnTable = AcidUtils.isTransactionalTable(tbl);
    boolean isMmTable = AcidUtils.isInsertOnlyTable(tbl);
    boolean isFullAcidTable = AcidUtils.isFullAcidTable(tbl);
    boolean isCompactionTable = AcidUtils.isCompactionTable(tbl.getParameters());

    if (conf.getBoolVar(ConfVars.FIRE_EVENTS_FOR_DML) && !tbl.isTemporary()) {
      newFiles = Collections.synchronizedList(new ArrayList<FileStatus>());
    }

    // Note: this assumes both paths are qualified; which they are, currently.
    if (((isMmTable || isDirectInsert || isFullAcidTable) && loadPath.equals(tbl.getPath())) || (loadFileType == LoadFileType.IGNORE)) {
      /**
       * some operations on Transactional tables (e.g. Import) write directly to the final location
       * and avoid the 'move' operation.  Since MoveTask does other things, setting 'loadPath' to be
       * the table/partition path indicates that the 'file move' part of MoveTask is not needed.
       */
      if (Utilities.FILE_OP_LOGGER.isDebugEnabled()) {
        Utilities.FILE_OP_LOGGER.debug(
            "not moving " + loadPath + " to " + tbl.getPath() + " (MM)");
      }

      //new files list is required only for event notification.
      if (newFiles != null) {
        newFiles.addAll(listFilesCreatedByQuery(loadPath, writeId, stmtId));
      }
    } else {
      // Either a non-MM query, or a load into MM table from an external source.
      Path tblPath = tbl.getPath();
      Path destPath = tblPath;
      if (isMmTable) {
        // We will load into MM directory, and hide previous directories if needed.
        destPath = new Path(destPath, isInsertOverwrite
            ? AcidUtils.baseDir(writeId) : AcidUtils.deltaSubdir(writeId, writeId, stmtId));
      }
      if (!isAcidIUDoperation && isFullAcidTable) {
        destPath = fixFullAcidPathForLoadData(loadFileType, destPath, writeId, stmtId, tbl);
      }
      Utilities.FILE_OP_LOGGER.debug("moving " + loadPath + " to " + tblPath
          + " (replace = " + loadFileType + ")");

      perfLogger.perfLogBegin("MoveTask", PerfLogger.FILE_MOVES);

      boolean isManaged = tbl.getTableType() == TableType.MANAGED_TABLE;

      if (loadFileType == LoadFileType.REPLACE_ALL && !isTxnTable) {
        //for fullAcid we don't want to delete any files even for OVERWRITE see HIVE-14988/HIVE-17361
        boolean isSkipTrash = MetaStoreUtils.isSkipTrash(tbl.getParameters());
        boolean needRecycle = !tbl.isTemporary()
                && ReplChangeManager.shouldEnableCm(getDatabase(tbl.getDbName()), tbl.getTTable());
        replaceFiles(tblPath, loadPath, destPath, tblPath, conf, isSrcLocal, isSkipTrash,
            newFiles, FileUtils.HIDDEN_FILES_PATH_FILTER, needRecycle, isManaged, isInsertOverwrite);
      } else {
        try {
          FileSystem fs = tbl.getDataLocation().getFileSystem(conf);
          copyFiles(conf, loadPath, destPath, fs, isSrcLocal, isAcidIUDoperation,
              loadFileType == LoadFileType.OVERWRITE_EXISTING, newFiles,
              tbl.getNumBuckets() > 0, isFullAcidTable, isManaged, isCompactionTable);
        } catch (IOException e) {
          throw new HiveException("addFiles: filesystem error in check phase", e);
        }
      }
      perfLogger.perfLogEnd("MoveTask", PerfLogger.FILE_MOVES);
    }

    // If there is no column stats gather stage present in the plan. So we don't know the accuracy of the stats or
    // auto gather stats is turn off explicitly. We need to reset the stats in both cases.
    if (resetStatistics || !this.getConf().getBoolVar(HiveConf.ConfVars.HIVE_STATS_AUTOGATHER)) {
      LOG.debug("Clear table column statistics and set basic statistics to false for " + tbl.getCompleteName());
      StatsSetupConst.setBasicStatsState(tbl.getParameters(), StatsSetupConst.FALSE);
    }

    try {
      if (isSkewedStoreAsSubdir) {
        SkewedInfo skewedInfo = tbl.getSkewedInfo();
        // Construct list bucketing location mappings from sub-directory name.
        Map<List<String>, String> skewedColValueLocationMaps = constructListBucketingLocationMap(
            tbl.getPath(), skewedInfo);
        // Add list bucketing location mappings.
        skewedInfo.setSkewedColValueLocationMaps(skewedColValueLocationMaps);
      }
    } catch (IOException e) {
      LOG.error("Failed loadTable", e);
      throw new HiveException(e);
    }

    EnvironmentContext environmentContext = null;
    if (!resetStatistics) {
      environmentContext = new EnvironmentContext();
      environmentContext.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE);
    }

    alterTable(tbl.getCatName(), tbl.getDbName(), tbl.getTableName(), tbl, false, environmentContext,
            true, ((writeId == null) ? 0 : writeId));

    if (AcidUtils.isTransactionalTable(tbl)) {
      addWriteNotificationLog(tbl, null, newFiles, writeId, null);
    } else {
      fireInsertEvent(tbl, null, (loadFileType == LoadFileType.REPLACE_ALL), newFiles);
    }

    perfLogger.perfLogEnd("MoveTask", PerfLogger.LOAD_TABLE);
  }
Load a directory into a Hive Table. - Alters existing content of table with
the contents of loadPath. - If table does not exist - an exception is
thrown - files in loadPath are moved into Hive. But the directory itself is
not removed.

@param loadPath
         Directory containing files to load into Table
@param tableName
         name of table to be loaded.
@param loadFileType
         if REPLACE_ALL - replace files in the table,
         otherwise add files to table (KEEP_EXISTING, OVERWRITE_EXISTING)
@param isSrcLocal
         If the source directory is LOCAL
@param isSkewedStoreAsSubdir
         if list bucketing enabled
@param isAcidIUDoperation true if this is an ACID based Insert [overwrite]/update/delete
@param resetStatistics should reset statistics as part of move.
@param writeId write ID allocated for the current load operation
@param stmtId statement ID of the current load statement
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java