Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/table/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def snapshots(self) -> pa.Table:
"committed_at": datetime.fromtimestamp(snapshot.timestamp_ms / 1000.0, tz=UTC),
"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.

"manifest_list": snapshot.manifest_list,
"summary": additional_properties,
}
Expand Down
15 changes: 15 additions & 0 deletions tests/table/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMem
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].

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())])))
assert tbl.inspect.snapshots().column("operation").to_pylist() == ["append"]

# 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]


@pytest.mark.parametrize("newest_first", [False, True])
def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None:
# Manifest entries are visited in manifest order, which is not chronological, so the
Expand Down
Loading