timothyw553 commented on code in PR #19147:
URL: https://github.com/apache/iceberg/pull/19147#discussion_r4704354907


##########
core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIO.java:
##########
@@ -157,6 +162,43 @@ public Iterable<FileInfo> listPrefix(String prefix) {
     };
   }
 
+  @Override
+  public Iterable<PrefixListingPage> listDirectory(String prefix) {
+    Preconditions.checkArgument(
+        prefix != null && prefix.endsWith("/"), "Directory prefix must end 
with '/': %s", prefix);
+    Path directory = new Path(prefix);
+    FileSystem fs = Util.getFs(directory, getConf());
+
+    return () -> {
+      try {
+        if (!fs.getFileStatus(directory).isDirectory()) {
+          throw new FileNotFoundException("Not a directory: " + prefix);
+        }
+
+        List<FileInfo> files = Lists.newArrayList();
+        List<String> subPrefixes = Lists.newArrayList();
+        for (FileStatus status : fs.listStatus(directory)) {
+          if (status.isDirectory()) {

Review Comment:
   what happens for ViewFS mount points here? if `fs.listStatus` returns a 
symlink with `isDirectory() == false`, wouldn't this report it as a 0-byte file 
and hide the subtree underneath? could we resolve symlinks first and add a 
regression test for listing across a ViewFS mount point?
   ```diff
   -          if (status.isDirectory()) {
   +          FileStatus target = status.isSymlink() ? 
fs.getFileStatus(status.getPath()) : status;
   +          if (target.isDirectory()) {
                subPrefixes.add(status.getPath() + "/");
              } else {
                files.add(
                    new FileInfo(
   -                    status.getPath().toString(), status.getLen(), 
status.getModificationTime()));
   +                    status.getPath().toString(), target.getLen(), 
target.getModificationTime()));
              }
   ```



##########
core/src/test/java/org/apache/iceberg/io/TestResolvingIO.java:
##########
@@ -130,6 +132,13 @@ public void delegateFileIOWithPrefixBasedSupport() throws 
IOException {
       assertThat(delegate.newInputFile(path.toString()).exists()).isTrue();
     }
 
+    String prefix = parent + "/";
+    assertThat(resolvingFileIO.supportsDirectoryListing(prefix)).isTrue();
+    
assertThat(resolvingFileIO.supportsDirectoryListing(paths.get(0).toString())).isFalse();

Review Comment:
   this negative case has no trailing `/`, so it returns `false` before 
consulting the delegate. if we removed 
`io(prefix).supportsDirectoryListing(prefix)` from `ResolvingFileIO`, these 
tests would still pass. could we add a test with a valid trailing-slash prefix 
whose delegate returns `false`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to