private Path processPathDepthInfo(final PathDepthInfo pd)
        throws IOException, MetastoreException {
      final Path currentPath = pd.p;
      final int currentDepth = pd.depth;
      if (currentDepth == partColNames.size()) {
        return currentPath;
      }
      List<FileStatus> fileStatuses = new ArrayList<>();
      RemoteIterator<FileStatus> fileIterator =
          RemoteIterators.filteringRemoteIterator(fs.listStatusIterator(currentPath),
            fileStatus -> HIDDEN_FILES_PATH_FILTER.accept(fileStatus.getPath()));
      while (fileIterator.hasNext()) {
        fileStatuses.add(fileIterator.next());
      }
      // found no files under a sub-directory under table base path; it is possible that the table
      // is empty and hence there are no partition sub-directories created under base path
      if (fileStatuses.size() == 0 && currentDepth > 0) {
        // since maxDepth is not yet reached, we are missing partition
        // columns in currentPath
        logOrThrowExceptionWithMsg(
            "MSCK is missing partition columns under " + currentPath.toString());
      } else {
        // found files under currentPath add them to the queue if it is a directory
        for (FileStatus fileStatus : fileStatuses) {
          if (!fileStatus.isDirectory()) {
            // found a file at depth which is less than number of partition keys
            logOrThrowExceptionWithMsg(
                "MSCK finds a file rather than a directory when it searches for "
                    + fileStatus.getPath().toString());
          } else {
            // found a sub-directory at a depth less than number of partition keys
            // validate if the partition directory name matches with the corresponding
            // partition colName at currentDepth
            Path nextPath = fileStatus.getPath();
            String[] parts = nextPath.getName().split("=");
            if (parts.length != 2) {
              logOrThrowExceptionWithMsg("Invalid partition name " + nextPath);
            } else if (!parts[0].equalsIgnoreCase(partColNames.get(currentDepth))) {
              logOrThrowExceptionWithMsg(
                  "Unexpected partition key " + parts[0] + " found at " + nextPath);
            } else {
              // add sub-directory to the work queue if maxDepth is not yet reached
              pendingPaths.add(new PathDepthInfo(nextPath, currentDepth + 1));
            }
          }
        }
      }
      return null;
    }
Assume that depth is 2, i.e., partition columns are a and b
tblPath/a=1  => throw exception
tblPath/a=1/file => throw exception
tblPath/a=1/b=2/file => return a=1/b=2
tblPath/a=1/b=2/c=3 => return a=1/b=2
tblPath/a=1/b=2/c=3/file => return a=1/b=2

@param basePath
         Start directory
@param allDirs
         This set will contain the leaf paths at the end.
@param partColNames
         Partition column names
@throws IOException
          Thrown if we can't get lists from the fs.
@throws MetastoreException ex
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreChecker.java