Spark: Fix NPE in RemoveOrphanFiles with prefix_listing for root table location(#16350)#16351
Open
liuliquan-marshal wants to merge 2 commits into
Open
Spark: Fix NPE in RemoveOrphanFiles with prefix_listing for root table location(#16350)#16351liuliquan-marshal wants to merge 2 commits into
liuliquan-marshal wants to merge 2 commits into
Conversation
pvary
reviewed
May 15, 2026
| new FileInfo("s3://bucket/data/a.parquet", 1L, 0L), | ||
| new FileInfo("s3://bucket/_temporary/attempt_x/b.parquet", 1L, 0L), | ||
| new FileInfo("s3://bucket/.staging/c.parquet", 1L, 0L)); | ||
| SupportsPrefixOperations mockIO = new StaticPrefixFileIO(entries); |
Contributor
There was a problem hiding this comment.
Much of the code is duplicated. Can we refactor that out?
Maybe something like:
private static List<String> walkBucket(String baseDir, FileInfo... entries) {
try (SupportsPrefixOperations fileIO = new StaticPrefixFileIO(ImmutableList.copyOf(entries))) {
List<String> foundFiles = Lists.newArrayList();
Predicate<FileInfo> fileFilter = fileInfo -> fileInfo.location().endsWith(".parquet");
assertThatCode(
() ->
FileSystemWalker.listDirRecursivelyWithFileIO(
fileIO, baseDir, null, fileFilter, foundFiles::add))
.doesNotThrowAnyException();
return foundFiles;
}
}
Author
There was a problem hiding this comment.
Thanks for reviewing, addressed this comment in the latest commit. PTAL.
pvary
reviewed
May 15, 2026
| assertThat(foundFiles).containsExactly("s3://bucket/data/a.parquet"); | ||
| } | ||
|
|
||
| private static class StaticPrefixFileIO implements SupportsPrefixOperations { |
Contributor
There was a problem hiding this comment.
Based on IntelliJ, this could be a java record
Contributor
There was a problem hiding this comment.
I've seen this alert as well, but I don't think we should do a one-off java record usage here.
Author
There was a problem hiding this comment.
I agree with nssalian. I think it's not quite appropriate to use java record. WDYT?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
fix #16350
Root table location(e.g. location is s3://bucket/ in metadata.json) when running orphan files removing with prefix_listing=true and S3FlieIO causes NPE. Orphan files removing will always fail in this situation.
This change adds null check when walk reaches the storage root. Besides this adds some tests.