RussellSpitzer commented on code in PR #7914:
URL: https://github.com/apache/iceberg/pull/7914#discussion_r1261736420
##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/actions/DeleteOrphanFilesSparkAction.java:
##########
@@ -303,6 +304,19 @@ private Dataset<String> listedFileDS() {
List<String> subDirs = Lists.newArrayList();
List<String> matchingFiles = Lists.newArrayList();
+ if (table.io() instanceof SupportsPrefixOperations) {
+ Iterator<org.apache.iceberg.io.FileInfo> iterator =
((SupportsPrefixOperations) table.io()).listPrefix(location).iterator();
Review Comment:
The idea is not to change the logic, but to change the structure of the
code. Basically you would take this code and the code after the exit and create
two functions (names are just examples)
```java
Dataset<String> listWithPrefix() {
List<String> matchingFiles = Lists.newArrayList();
Iterator<org.apache.iceberg.io.FileInfo> iterator =
((SupportsPrefixOperations)
table.io()).listPrefix(location).iterator();
while (iterator.hasNext()) {
org.apache.iceberg.io.FileInfo fileInfo = iterator.next();
if (fileInfo.createdAtMillis() < olderThanTimestamp) {
matchingFiles.add(fileInfo.location());
}
}
JavaRDD<String> matchingFileRDD =
sparkContext().parallelize(matchingFiles, 1);
return spark().createDataset(matchingFileRDD.rdd(), Encoders.STRING());
}
Dataset<String> listWithoutPrefix() {
List<String> matchingFiles = Lists.newArrayList();
Predicate<FileStatus> predicate = file -> file.getModificationTime() <
olderThanTimestamp;
PathFilter pathFilter =
PartitionAwareHiddenPathFilter.forSpecs(table.specs());
// list at most MAX_DRIVER_LISTING_DEPTH levels and only dirs that have
// less than MAX_DRIVER_LISTING_DIRECT_SUB_DIRS direct sub dirs on the
driver
listDirRecursively(
location,
predicate,
hadoopConf.value(),
MAX_DRIVER_LISTING_DEPTH,
MAX_DRIVER_LISTING_DIRECT_SUB_DIRS,
subDirs,
pathFilter,
matchingFiles);
JavaRDD<String> matchingFileRDD =
sparkContext().parallelize(matchingFiles, 1);
if (subDirs.isEmpty()) {
return spark().createDataset(matchingFileRDD.rdd(), Encoders.STRING());
}
int parallelism = Math.min(subDirs.size(), listingParallelism);
JavaRDD<String> subDirRDD = sparkContext().parallelize(subDirs,
parallelism);
Broadcast<SerializableConfiguration> conf =
sparkContext().broadcast(hadoopConf);
ListDirsRecursively listDirs = new ListDirsRecursively(conf,
olderThanTimestamp, pathFilter);
JavaRDD<String> matchingLeafFileRDD = subDirRDD.mapPartitions(listDirs);
JavaRDD<String> completeMatchingFileRDD =
matchingFileRDD.union(matchingLeafFileRDD);
return spark().createDataset(completeMatchingFileRDD.rdd(),
Encoders.STRING());
}
```
Then you change listedFilesDS
```java
listedFileDS() {
If (table.io supportsPrefix)
files = listPrefix()
else
files = listNoPrefix()
}
return files
}
```
--
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]