Skip to content

feat(table): Table Metadata V3 support - #585

Merged
zeroshade merged 4 commits into
apache:mainfrom
dttung2905:update-metadata-builder-for-v3
Oct 21, 2025
Merged

zeroshade merged 4 commits into
apache:mainfrom
dttung2905:update-metadata-builder-for-v3

Conversation

@dttung2905

@dttung2905 dttung2905 commented Oct 2, 2025 •

Copy link
Copy Markdown
Contributor

List of changes implemented

  • Add NextRowID field to commonMetadata
  • Add FirstRowID field to Snapshot struct
  • Add v3 metadata parsing/ validation

Comment thread table/metadata.go Outdated
func initMetadataV3Deser() *metadataV3 {
return &metadataV3{
LastSeqNum: -1,
NextRowIDValue: 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we also init this to -1? if we init to 0, we cannot tell if it was sent or not, 0 is a valid value, missing is not according to the spec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I think you are right about this. I have updated the PR to reflect this

@twuebi twuebi mentioned this pull request Oct 6, 2025
48 of 58 tasks
@dttung2905 dttung2905 changed the title [NOT READY FOR REVIEW YET]: Update metadatabuilder to support iceberg v3 spec feat(table): Table Metadata V3 support Oct 7, 2025
@dttung2905
dttung2905 marked this pull request as ready for review October 7, 2025 21:25
Comment thread table/metadata.go Outdated
Comment on lines +1785 to +1794
func (m *metadataV3) checkLastSequenceNumber() error {
for _, snap := range m.SnapshotList {
if snap.SequenceNumber > m.LastSequenceNumber() {
return fmt.Errorf("%w: snapshot %d has sequence number %d which is greater than last-sequence-number %d",
ErrInvalidMetadata, snap.SnapshotID, snap.SequenceNumber, m.LastSequenceNumber())
}
}

return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way to not have this function twice? maybe by defining another interface which defines a func LastSequenceNumber() and implements this which would be part of both metadata v2 & v3?

Comment thread table/metadata.go Outdated
Comment on lines +756 to +759
func (b *MetadataBuilder) SetNextRowID(nextRowID int64) *MetadataBuilder {
b.nextRowID = &nextRowID
return b
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need a setter here? On what occasion would we want to set this from the outside?

It probably makes sense to not expose this to library users. My current understanding is that we only need to increment this in AddSnapshot based on the number of added rows in the snapshot.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looking at iceberg-java, there's only a write to nextRowId in Builder::addSnapshot which does:

this.nextRowId += snapshot.addedRows();

other assignments are either carryover from base metadata to builder or initial assignment to initial row id.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm in agreement here, we shouldn't have this setter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you both are spot on about this 😄

Comment thread table/metadata.go Outdated
Comment on lines +1732 to +1735
if m.NextRowIDValue == -1 {
return 0 // RFor v1/v2 compatibility when field is missing
}
return m.NextRowIDValue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if m.NextRowIDValue == -1 {
return 0 // RFor v1/v2 compatibility when field is missing
}
return m.NextRowIDValue
return max(0, m.NextRowIDValue)

maybe?

Comment thread table/metadata.go Outdated
Comment on lines +1797 to +1802
if m.NextRowIDValue == -1 {
return fmt.Errorf("%w: next-row-id is required for v3 tables", ErrInvalidMetadata)
}
if m.NextRowIDValue < -1 {
return fmt.Errorf("%w: next-row-id must be non-negative, got %d", ErrInvalidMetadata, m.NextRowIDValue)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this feels like it could be rolled into the same check or otherwise avoid needing two checks

@zeroshade

Copy link
Copy Markdown
Member

One thing to fix first:
image

@dttung2905
dttung2905 force-pushed the update-metadata-builder-for-v3 branch from 0207ed3 to 44cd158 Compare October 20, 2025 18:41
@dttung2905

Copy link
Copy Markdown
Contributor Author

Thanks @zeroshade . I see this. NewMetadataBuilder() require an int as introduced by a recent commit. I just rebased from main 🙏

@zeroshade
zeroshade merged commit 3a7fe95 into apache:main Oct 21, 2025
@laskoviymishka laskoviymishka mentioned this pull request Apr 3, 2026
96 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants