Skip to content

Writing v3 Table Metadata #3551

Open
rambleraptor wants to merge 1 commit into
apache:mainfrom
rambleraptor:v3-metadata-write
Open

Writing v3 Table Metadata #3551
rambleraptor wants to merge 1 commit into
apache:mainfrom
rambleraptor:v3-metadata-write

Conversation

@rambleraptor

@rambleraptor rambleraptor commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Rationale for this change

We're far enough into v3 (with a ratified spec!) that we should consider writing v3 table metadata.

Are these changes tested?

Added a unit test and fixed up the places where we were expecting errors

Are there any user-facing changes?

  • Added v3 table metadata writing support

@rambleraptor rambleraptor requested a review from kevinjqliu June 22, 2026 22:04

@ebyhr ebyhr left a comment

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.

Does it make sense to add an integration test that Spark reads v3 tables written by PyIceberg?

@abnobdoss abnobdoss left a comment

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.

This is awesome - I'm excited for v3 table write support! Left a few minor comments; apologies if I misunderstood anything here.

INITIAL_SPEC_ID = 0
DEFAULT_SCHEMA_ID = 0

SUPPORTED_TABLE_FORMAT_VERSION = 2

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.

Does this need to change?

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.

Does this PR only allow new v3 tables or does it also enable v1/v2 tables to be upgraded to v3?

next_row_id: int | None = Field(alias="next-row-id", default=None)
"""A long higher than all assigned row IDs; the next snapshot's `first-row-id`."""

def model_dump_json(self, exclude_none: bool = True, exclude: Any | None = None, by_alias: bool = True, **kwargs: Any) -> str:

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 row lineage fully wired up? If I'm not mistaken, row lineage would be a pre-requisite for v3 enablement?

@moomindani

Copy link
Copy Markdown

The v3 spec marks next-row-id as required in table metadata. With this change, new_table_metadata constructs TableMetadataV3 with next_row_id=None, and since model_dump_json uses exclude_none, newly created v3 tables are written without next-row-id. Would it make sense to initialize it to 0 as part of this PR? (Upgrades to v3 are tracked separately in #3622, and the remaining write-side pieces in #3620 / #3621.)

moomindani added a commit to moomindani/iceberg-python that referenced this pull request Jul 8, 2026
Allow upgrade_table_version(3) and initialize next-row-id to 0 on
upgrade, per the spec's Row Lineage for Upgraded Tables. Persisting
the upgraded metadata still requires V3 metadata serialization (apache#3551).

Closes apache#3622

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
moomindani added a commit to moomindani/iceberg-python that referenced this pull request Jul 8, 2026
Allow upgrade_table_version(3) and initialize next-row-id to 0 on
upgrade, per the spec's Row Lineage for Upgraded Tables. Persisting
the upgraded metadata still requires V3 metadata serialization (apache#3551).

Closes apache#3622
"""A long higher than all assigned row IDs; the next snapshot's `first-row-id`."""

def model_dump_json(self, exclude_none: bool = True, exclude: Any | None = None, by_alias: bool = True, **kwargs: Any) -> str:
raise NotImplementedError("Writing V3 is not yet supported, see: https://github.com/apache/iceberg-python/issues/1551")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One edge case this change surfaces: the v3 spec allows an optional encryption-keys list in table metadata, and the Java TableMetadataParser writes it when present. PyIceberg doesn't model the field, and the pydantic models ignore unknown fields, so it's dropped at parse time. With serialization enabled, loading a v3 table that carries encryption-keys and committing any update would rewrite the metadata without the keys, which would break an encrypted table. Would it make sense to add a passthrough encryption-keys field to TableMetadataV3 so it round-trips, even before encryption is actually supported?

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.

4 participants