private void deleteOldPathForReplace(Path destPath, Path oldPath, HiveConf conf, boolean purge,
      PathFilter pathFilter, boolean isNeedRecycle) throws HiveException {
    Utilities.FILE_OP_LOGGER.debug("Deleting old paths for replace in " + destPath
        + " and old path " + oldPath);
    boolean isOldPathUnderDestf = false;
    try {
      FileSystem oldFs = oldPath.getFileSystem(conf);
      FileSystem destFs = destPath.getFileSystem(conf);
      // if oldPath is destf or its subdir, its should definitely be deleted, otherwise its
      // existing content might result in incorrect (extra) data.
      // But not sure why we changed not to delete the oldPath in HIVE-8750 if it is
      // not the destf or its subdir?
      isOldPathUnderDestf = isSubDir(oldPath, destPath, oldFs, destFs, false);
      if (isOldPathUnderDestf && oldFs.exists(oldPath)) {
        cleanUpOneDirectoryForReplace(oldPath, oldFs, pathFilter, conf, purge, isNeedRecycle);
      }
    } catch (IOException e) {
      if (isOldPathUnderDestf) {
        // if oldPath is a subdir of destf but it could not be cleaned
        throw new HiveException("Directory " + oldPath.toString()
            + " could not be cleaned up.", e);
      } else {
        //swallow the exception since it won't affect the final result
        LOG.warn("Directory " + oldPath.toString() + " cannot be cleaned: " + e, e);
      }
    }
  }
Replaces files in the partition with new data set specified by srcf. Works
by renaming directory of srcf to the destination file.
srcf, destf, and tmppath should resident in the same DFS, but the oldPath can be in a
different DFS.

@param tablePath path of the table.  Used to identify permission inheritance.
@param srcf
         Source directory to be renamed to tmppath. It should be a
         leaf directory where the final data files reside. However it
         could potentially contain subdirectories as well.
@param destf
         The directory where the final data needs to go
@param oldPath
         The directory where the old data location, need to be cleaned up.  Most of time, will be the same
         as destf, unless its across FileSystem boundaries.
@param purge
         When set to true files which needs to be deleted are not moved to Trash
@param isSrcLocal
         If the source directory is LOCAL
@param newFiles
         Output the list of new files replaced in the destination path
@param isManaged
         If the table is managed.
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java