Skip to content

Conversation

@ajantha-bhat
Copy link
Member

@ajantha-bhat ajantha-bhat commented May 27, 2025

Fixes an edge case where deleted entires information is not carried to next snapshot. So, incremental stats compute was wrong for this copy on write case. Fix is to apply incremental stats compute snapshot by snapshot for its added manifest.

Also fallback when stats file exist for table but not for current snapshot chain, instead of throwing exception.

Fixes: #13155

@lirui-apache
Copy link
Contributor

@ajantha-bhat Thanks for working on this! Left some comments.

try (CloseableIterable<PartitionStats> oldStats =
readPartitionStatsFile(schema(partitionType), Files.localInput(previousStatsFile.path()))) {
readPartitionStatsFile(
schema(partitionType), table.io().newInputFile(previousStatsFile.path()))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just using the FileIO as pointed out in the PR.
Unrelated to this bug fix. But related to this feature.

id ->
table.snapshot(id).allManifests(table.io()).stream()
.filter(file -> file.snapshotId().equals(id)))
.collect(Collectors.toList());
Copy link
Member Author

@ajantha-bhat ajantha-bhat May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also checked that if snapshots are expired, we cannot find previous stats for the table in the caller.
So, it will fallback to full compute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that, because of snapshot id filter,
Each snapshot's added manifest files will be considered only once for compute. So, reused manifests won't be considered again. If manifests are rewritten, entries will be marked as EXISTING and won't be considered for incremental compute from existing logic in collectStatsForManifest.

So, IMO it works for all the scenarios now and we have testcase to cover all the scenarios.

@ajantha-bhat ajantha-bhat marked this pull request as ready for review May 28, 2025 11:46
@ajantha-bhat ajantha-bhat changed the title Core: Fix incremental compute of partition stats Core: Fix incremental compute of partition stats with COW deletes May 28, 2025
@ajantha-bhat ajantha-bhat requested a review from pvary May 28, 2025 11:49
@ajantha-bhat
Copy link
Member Author

@lirui-apache: Could you please take another look at the fix, verify and approve the PR if it looks good for you?

Copy link
Contributor

@lirui-apache lirui-apache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @ajantha-bhat . I only have a minor comment. But I have another question related to the feature and may be worth another PR. In PartitionStatsHandler::latestStatsFile, we throw exception if there is any previous stats file but not reachable via the parent snapshot pointers. I think this means we don't allow gaps in snapshot history, which can be common when using tags. Won't it be more user friendly to just fall back to a full compute in that case?

// So, for incremental computation, gather the manifests added by each snapshot
// instead of relying solely on those from the latest snapshot.
List<ManifestFile> manifests =
snapshotIdsRange.stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: How about just call SnapshotUtil::ancestorsBetween and iterate through the ancestors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@ajantha-bhat
Copy link
Member Author

But I have another question related to the feature and may be worth another PR. In PartitionStatsHandler::latestStatsFile, we throw exception if there is any previous stats file but not reachable via the parent snapshot pointers. I think this means we don't allow gaps in snapshot history, which can be common when using tags. Won't it be more user friendly to just fall back to a full compute in that case?

Great. I didn't think of this case before. Hence, added that exception before. I made it to fallback now and added the test.

@ajantha-bhat
Copy link
Member Author

@pvary: Thanks for previous review and approval. Please take another look after @lirui-apache's approval.

Copy link
Contributor

@lirui-apache lirui-apache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating. LGTM

@pvary pvary merged commit 2ada622 into apache:main May 29, 2025
42 checks passed
@pvary pvary changed the title Core: Fix incremental compute of partition stats with COW deletes Core: Fix incremental compute of partition stats for various edge cases May 29, 2025
@pvary
Copy link
Contributor

pvary commented May 29, 2025

Merged to main.
Thanks for the fix @ajantha-bhat and @lirui-apache for reporting and reviewing!

devendra-nr pushed a commit to devendra-nr/iceberg that referenced this pull request Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incrementally computing partition stats can miss deleted files

3 participants