[SPARK-52339][SQL] Fix comparison of InMemoryFileIndex
instances
#51043
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.
What changes were proposed in this pull request?
This PR changes
InMemoryFileIndex#equals
to compare a non-distinct collection of root paths rather than a distinct set of root paths. Without this change,InMemoryFileIndex#equals
considers the following two collections of root paths to be equal, even though they represent a different number of rows:Why are the changes needed?
The bug can cause correctness issues, e.g.
In the above example, df1 and df2 were created with a different number of paths: df1 has 2, and df2 has 3. But since the distinct set of root paths is the same (e.g.,
Set("/tmp/test") == Set("/tmp/test"))
, the two dataframes are considered equal. Thus, when df1 is persisted, df2 uses df1's cached plan.The same bug also causes inappropriate exchange reuse.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New unit test.
Was this patch authored or co-authored using generative AI tooling?
No.