Correctly remove position delete files on optimize #27756
+28
−42
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.
Description
Fixes #27732 . Corrects an underlying bug that only affected predicates using the
$partitioncolumn.I updated an existing test to verify this behavior, as the test previously obscured this bug by using
EXECUTE REMOVE_ORPHAN_FILES, which removes the dangling deletes that should've been removed byOPTIMIZE.Additional context and related issues
I believe the logic used to determine whether a position delete is fully applied is faulty, but I could use a careful review here to verify my understanding.
From the comment on line 348:
OPTIMIZE supports only enforced predicates which select whole partitions, so if there is no path or fileModifiedTime predicate, then we can clean up position deletesThis seems to contradict the logic on line 351:
case POSITION_DELETES -> partitionDomain.isAll() && pathDomain.isAll() && fileModifiedTimeDomain.isAll();As I understand this,
partitionDomain.isAll()just checks whether there is any filter on the$partitioncolumn. As position delete files are only granular to the partition level, just checking the path and fileModifiedTime domains should be sufficient, as that would mean we're fully covering the partition.For predicates on the filter column (i.e. not using
$partition),partitionDomain.isAll()is true, because we are not explicitly filtering on the$partitioncolumn. This is why the bug doesn't surface for these predicates.Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: