apache/hadoop · error · PathIsDirectoryException

Is a directory

Error message

Is a directory

What it means

PathIsDirectoryException ('Is a directory') thrown by Cat.processPath (Display.java:91) when 'hadoop fs -cat' is applied to a directory. cat copies bytes of a single file to stdout (after optionally toggling checksum verification via -ignoreCrc), and a directory has no byte stream, so the shell rejects it per-path before opening.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java:91

    public static final String USAGE = "[-ignoreCrc] <src> ...";
    public static final String DESCRIPTION =
      "Fetch all files that match the file pattern <src> " +
      "and display their content on stdout.\n";

    private boolean verifyChecksum = true;

    @Override
    protected void processOptions(LinkedList<String> args)
    throws IOException {
      CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, "ignoreCrc");
      cf.parse(args);
      verifyChecksum = !cf.getOpt("ignoreCrc");
    }

    @Override
    protected void processPath(PathData item) throws IOException {
      if (item.stat.isDirectory()) {
        throw new PathIsDirectoryException(item.toString());
      }
      
      item.fs.setVerifyChecksum(verifyChecksum);
      printToStdout(getInputStream(item));
    }

    private void printToStdout(InputStream in) throws IOException {
      try {
        IOUtils.copyBytes(in, out, getConf(), false);
      } finally {
        in.close();
      }
    }

    protected InputStream getInputStream(PathData item) throws IOException {
      // Always do sequential reads;
      return item.openForSequentialIO();
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Glob the files inside: 'hadoop fs -cat "/data/somedir/*"' (quote so Hadoop, not the shell, expands it)
  2. Or target a specific file: 'hadoop fs -cat /data/somedir/part-00000'
  3. For a quick size/structure look, use 'hadoop fs -ls /data/somedir' first
  4. For partitioned data, iterate the part files or use 'hadoop fs -getmerge' to a local file

Example fix

# before
hadoop fs -cat /table/dt=2026-01-01     # Is a directory

# after
hadoop fs -cat '/table/dt=2026-01-01/*'
Defensive patterns

Strategy: validation

Validate before calling

if (item.stat.isDirectory()) {
  throw new PathIsDirectoryException(item.toString());
}

Type guard

static boolean isReadableFile(FileStatus st) {
  return st != null && st.isFile();
}

Try / catch

try {
  IOUtils.copyBytes(item.openFile(), out, conf);
} catch (PathIsDirectoryException e) {
  // glob the directory's files and cat those instead
}

Prevention

When it happens

Trigger: 'hadoop fs -cat /data/somedir'; an unquoted glob that matched nothing leaving a literal directory arg; passing a partition root (e.g. /table/dt=2026-01-01) that is a directory.

Common situations: Inspecting Hive/Spark partition paths where the partition is a directory of part files; quick data checks that assume a file but the path is a directory; piping 'hadoop fs -cat $P' with P pointing at a directory.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/2cc5145751659d34. Report an issue: GitHub.