Skip to content

Return null operation for snapshots without a summary - #4477

Open
rahulsmahadev wants to merge 3 commits into
apache:mainfrom
rahulsmahadev:rahul/inspect-snapshots-operation-null
Open

rahulsmahadev wants to merge 3 commits into
apache:mainfrom
rahulsmahadev:rahul/inspect-snapshots-operation-null

Conversation

@rahulsmahadev

@rahulsmahadev rahulsmahadev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Bug: a snapshot can have no summary, and then it has no operation. The summary is optional in v1, and a v1 table upgraded to v2 keeps such snapshots. Table.inspect.snapshots() then shows the text "None" as the operation:

# tbl is a format v1 table whose snapshot has no summary
tbl.inspect.snapshots().column("operation").to_pylist()
# ['None'], expected [None]

snapshots() sets operation = None in this case, then stores str(operation) in the nullable column.

Fix: store operation as is, so a missing summary gives a null cell. summary is already null.

Java: Spark's .snapshots scan uses SnapshotsTable, which returns the operation parsed by SnapshotParser unchanged, including null (TestSnapshotJson checks the null). This PR fixes the equivalent PyIceberg inspection output.

Still different from Java, not changed here: "summary": {} reads as operation overwrite (with a warning, as in Summary), while Java reads it as no summary.

Are these changes tested?

Yes. test_inspect_snapshots_operation_is_null_without_summary in tests/table/test_inspect.py checks that a snapshot reports append and, after its summary is removed from the table metadata, that operation and summary are null. It fails on main with ['None'] where [None] is expected, and passes with this change.

Are there any user-facing changes?

Yes, operation is null instead of the string None for snapshots without a summary. Please add the changelog label.

This pull request and its description were written by Isaac.

rahulsmahadev and others added 2 commits November 23, 2026 17:18
A format v1 snapshot can have no summary, so it has no operation.
inspect.snapshots() stored str(operation), which put the text "None" in
the nullable operation column. Store the operation as is, so the cell
is null, as Java's SnapshotsTable does.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

@ebyhr could you take a look when you have a chance? Thanks!

"snapshot_id": snapshot.snapshot_id,
"parent_id": snapshot.parent_snapshot_id,
"operation": str(operation),
"operation": operation,

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.

The fix looks right and matches Java's SnapshotsTable.

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.

Thanks for checking against Java.

assert files[0]["column_sizes"] is None


def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCatalog) -> None:

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.

The test can be much shorter. It doesn't need the metadata file rewrite, or the file:// handling. Replacing the summary on the in-memory metadata exercises the same code path:

def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCatalog) -> None:
    schema = Schema(NestedField(1, "x", LongType(), required=False))
    tbl = catalog.create_table("default.snapshot_without_summary", schema)
    tbl.append(pa.table({"x": [1]}, schema=pa.schema([pa.field("x", pa.int64())])))

    # The summary is optional in v1, so a snapshot without one has no operation
    snapshot = tbl.metadata.snapshots[0].model_copy(update={"summary": None})
    tbl.metadata = tbl.metadata.model_copy(update={"snapshots": [snapshot]})

    snapshots = tbl.inspect.snapshots()
    assert snapshots.column("operation").to_pylist() == [None]
    assert snapshots.column("summary").to_pylist() == [None]

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.

Thanks, much simpler. Switched to your version and kept one line from the old test that checks append before the summary is removed. It still fails on main with ['None'] == [None].

Replace the summary on the in-memory metadata instead of rewriting the
metadata file, as suggested in review.

Co-authored-by: Isaac <no-reply@databricks.com>

@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.

Looks good to me.

@kevinjqliu @Fokko @geruh Could you review this PR?

This branch has not been deployed

No deployments
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.

2 participants