private AcidDirectory getAcidStateForWorker(CompactionInfo ci, StorageDescriptor sd,
                                              ValidCompactorWriteIdList tblValidWriteIds) throws IOException, InterruptedException {
    if (CompactorUtil.runJobAsSelf(ci.runAs)) {
      return AcidUtils.getAcidState(null, new Path(sd.getLocation()), conf,
          tblValidWriteIds, Ref.from(false), true);
    }

    UserGroupInformation ugi = UserGroupInformation.createProxyUser(ci.runAs, UserGroupInformation.getLoginUser());
    try {
      return ugi.doAs((PrivilegedExceptionAction<AcidDirectory>) () ->
          AcidUtils.getAcidState(null, new Path(sd.getLocation()), conf, tblValidWriteIds,
              Ref.from(false), true));
    } finally {
      try {
        FileSystem.closeAllForUGI(ugi);
      } catch (IOException exception) {
        LOG.error("Could not clean up file-system handles for UGI: " + ugi + " for " + ci.getFullPartitionName(),
            exception);
      }
    }
  }
Just AcidUtils.getAcidState, but with impersonation if needed.
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/service/AcidCompactionService.java