@InterfaceAudience.Private @InterfaceStability.Evolving public class DescendantsIterator extends Object implements org.apache.hadoop.fs.RemoteIterator<S3AFileStatus>
DescendantsIterator is a RemoteIterator that implements
pre-ordering breadth-first traversal (BFS) of a path and all of its
descendants recursively. After visiting each path, that path's direct
children are discovered by calling MetadataStore.listChildren(Path).
Each iteration returns the next direct child, and if that child is a
directory, also pushes it onto a queue to discover its children later.
For example, assume the consistent store contains metadata representing this
file system structure:
/dir1
|-- dir2
| |-- file1
| `-- file2
`-- dir3
|-- dir4
| `-- file3
|-- dir5
| `-- file4
`-- dir6
Consider this code sample:
final PathMetadata dir1 = get(new Path("/dir1"));
for (DescendantsIterator descendants = new DescendantsIterator(dir1);
descendants.hasNext(); ) {
final FileStatus status = descendants.next().getFileStatus();
System.out.printf("%s %s%n", status.isDirectory() ? 'D' : 'F',
status.getPath());
}
The output is:
D /dir1 D /dir1/dir2 D /dir1/dir3 F /dir1/dir2/file1 F /dir1/dir2/file2 D /dir1/dir3/dir4 D /dir1/dir3/dir5 F /dir1/dir3/dir4/file3 F /dir1/dir3/dir5/file4 D /dir1/dir3/dir6
| Constructor and Description |
|---|
DescendantsIterator(MetadataStore ms,
PathMetadata meta)
Creates a new
DescendantsIterator. |
public DescendantsIterator(MetadataStore ms, PathMetadata meta) throws IOException
DescendantsIterator.ms - the associated MetadataStoremeta - base path for descendants iteration, which will be the first
returned during iteration (except root). Null makes empty iterator.IOException - if errors happen during metadata store listingpublic boolean hasNext()
throws IOException
hasNext in interface org.apache.hadoop.fs.RemoteIterator<S3AFileStatus>IOExceptionpublic S3AFileStatus next() throws IOException
next in interface org.apache.hadoop.fs.RemoteIterator<S3AFileStatus>IOExceptionCopyright © 2008–2022 Apache Software Foundation. All rights reserved.