Repository navigation
Return null operation for snapshots without a summary - #4477
rahulsmahadev wants to merge 3 commits into
Conversation
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>
|
@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, |
There was a problem hiding this comment.
The fix looks right and matches Java's SnapshotsTable.
There was a problem hiding this comment.
Thanks for checking against Java.
| assert files[0]["column_sizes"] is None | ||
|
|
||
|
|
||
| def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCatalog) -> None: |
There was a problem hiding this comment.
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]There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Looks good to me.
@kevinjqliu @Fokko @geruh Could you review this PR?
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:snapshots()setsoperation = Nonein this case, then storesstr(operation)in the nullable column.Fix: store
operationas is, so a missing summary gives a null cell.summaryis already null.Java: Spark's
.snapshotsscan usesSnapshotsTable, which returns the operation parsed bySnapshotParserunchanged, including null (TestSnapshotJsonchecks the null). This PR fixes the equivalent PyIceberg inspection output.Still different from Java, not changed here:
"summary": {}reads as operationoverwrite(with a warning, as inSummary), while Java reads it as no summary.Are these changes tested?
Yes.
test_inspect_snapshots_operation_is_null_without_summaryintests/table/test_inspect.pychecks that a snapshot reportsappendand, after its summary is removed from the table metadata, thatoperationandsummaryare null. It fails on main with['None']where[None]is expected, and passes with this change.Are there any user-facing changes?
Yes,
operationis null instead of the stringNonefor snapshots without a summary. Please add thechangeloglabel.This pull request and its description were written by Isaac.