Core: Fix SnapshotUtil.schemaFor to look up schema by id#16892
Draft
thswlsqls wants to merge 1 commit into
Draft
Core: Fix SnapshotUtil.schemaFor to look up schema by id#16892thswlsqls wants to merge 1 commit into
thswlsqls wants to merge 1 commit into
Conversation
schemaFor(TableMetadata, ref) read the snapshot schema with metadata.schemas().get(snapshot.schemaId()). schemas() returns a List<Schema>, so the schema id was used as a list index. When schema ids no longer match list positions (for example after expireSnapshots with cleanExpiredMetadata removes an older schema), this returns the wrong schema, or throws IndexOutOfBoundsException when the id is past the list size. Look the schema up by id via metadata.schemasById(), mirroring the sibling schemaFor(Table, long) in the same class, and guard a missing id with the same checkState message. Generated-by: Claude Code
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
SnapshotUtil.schemaFor(TableMetadata, ref)read the snapshot schema withmetadata.schemas().get(snapshot.schemaId()).metadata.schemas()returns aList<Schema>, so the schema id was used as a list index.IndexOutOfBoundsExceptionwhen the id is past the list size.expireSnapshots().cleanExpiredMetadata(true)removes an older unreferenced schema.metadata.schemasById(), mirroring the siblingschemaFor(Table, long), including itscheckStateguard for a missing id.MergingSnapshotProducer.apply, passes a branch ref, and branch refs return the table schema earlier in the method. The buggy line is reachable only for tag refs, so this removes an internal inconsistency rather than a live failure.Testing done
TestSnapshotUtil#schemaForTagWithMetadata(wrong-schema case) andschemaForTagWithMetadataSchemaIdBeyondListSize(IndexOutOfBounds case)../gradlew :iceberg-core:test --tests "org.apache.iceberg.util.TestSnapshotUtil"— 14 tests passed../gradlew :iceberg-core:spotlessCheck :iceberg-core:checkstyleMain :iceberg-core:checkstyleTest :iceberg-core:revapi— passed (revapi backward compatible).ArrayIndexOutOfBoundsException); restored, both pass.