public List<Path> clean(CleanupRequest cr) throws MetaException {
    Ref<List<Path>> removedFiles = Ref.from(new ArrayList<>());
    try {
      Callable<List<Path>> cleanUpTask;
      cleanUpTask = () -> removeFiles(cr);

      if (CompactorUtil.runJobAsSelf(cr.runAs())) {
        removedFiles.value = cleanUpTask.call();
      } else {
        LOG.info("Cleaning as user {} for {}", cr.runAs(), cr.getFullPartitionName());
        UserGroupInformation ugi = UserGroupInformation.createProxyUser(cr.runAs(),
                UserGroupInformation.getLoginUser());
        try {
          ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
            removedFiles.value = cleanUpTask.call();
            return null;
          });
        } finally {
          try {
            FileSystem.closeAllForUGI(ugi);
          } catch (IOException exception) {
            LOG.error("Could not clean up file-system handles for UGI: {} for {}",
                    ugi, cr.getFullPartitionName(), exception);
          }
        }
      }
    } catch (Exception ex) {
      LOG.error("Caught exception when cleaning, unable to complete cleaning of {} due to {}", cr,
              StringUtils.stringifyException(ex));
    }
    return removedFiles.value;
  }
A runnable class which takes in cleaningRequestHandler and cleaning request and deletes the files
according to the cleaning request.
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/FSRemover.java