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,
"manifest_list": snapshot.manifest_list,
"summary": additional_properties,
}
Expand Down
28 changes: 27 additions & 1 deletion tests/table/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from pathlib import PosixPath
from pathlib import Path, PosixPath
from typing import Any

import pyarrow as pa
Expand Down Expand Up @@ -104,6 +104,32 @@ 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:
import json

# The summary is optional in format v1 and holds the operation, so a snapshot without one has no
# operation: the nullable column must hold null, not the text "None"
schema = Schema(NestedField(1, "x", LongType(), required=False))
arrow_table = pa.table({"x": [1, 2]}, schema=pa.schema([pa.field("x", pa.int64(), nullable=True)]))

v2 = catalog.create_table("default.v2_snapshot_operation", schema, properties={"format-version": "2"})
v2.append(arrow_table)
assert v2.inspect.snapshots().column("operation").to_pylist() == ["append"]

v1 = catalog.create_table("default.v1_snapshot_without_summary", schema, properties={"format-version": "1"})
v1.append(arrow_table)
metadata_path = Path(v1.metadata_location.removeprefix("file://"))
metadata = json.loads(metadata_path.read_text())
for snapshot in metadata["snapshots"]:
del snapshot["summary"]
metadata_path.write_text(json.dumps(metadata))

v1 = catalog.load_table("default.v1_snapshot_without_summary")
snapshots = v1.inspect.snapshots().to_pylist()
assert [row["operation"] for row in snapshots] == [None]
assert [row["summary"] for row in snapshots] == [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