Repository navigation
Conversation
…last log entry The snapshot log is not guaranteed to be ordered by timestamp, so iterating it in reverse could return an older snapshot when entries were appended out of order.
Fokko
left a comment
There was a problem hiding this comment.
Thanks @sohailshk, nice catch and the Java parity reasoning in the description makes it easy to follow.
Verified: the new test fails on main and passes with this change. One comment:
pyiceberg/table/__init__.py(snapshot_as_of_timestamp): the>=on equal timestamps changes behavior from first-wins to last-wins on ties. The description makes a compelling case (later entry is the state that was actually current), just flagging it here since Java keeps the first entry on ties, so someone diffing behavior across implementations will notice.
CI is green too, LGTM!
|
Thanks for the review. I'm keeping I looked at the Java side: |
Rationale for this change
Table.snapshot_as_of_timestampwalks the snapshot log backwards and returns the first entry at or before the timestamp, which assumes the log is ordered by timestamp. The spec does not guarantee that, and Java's TableMetadata accepts a log entry up to one minute older than the previous one, so inside that skew window the lookup can return an older snapshot. Java fixed the same assumption inSnapshotUtil.nullableSnapshotIdAsOfTime(apache/iceberg#17360, "finding the entry with the maximum timestamp <= requested timestamp").This picks the entry with the largest timestamp that is at or before (or strictly before, with
inclusive=False) the requested one. On equal timestamps the later entry wins, unlike Java which keeps the first: PyIceberg logs every snapshot added in one transaction with its own timestamp_ms, so two can share a millisecond and the later one is the state that was actually current. Later-wins is also what PyIceberg and Java did before.inspect.metadata_log_entriesuses the same lookup forlatest_snapshot_id.Are these changes tested?
Yes,
test_snapshot_by_timestamp_with_unordered_snapshot_login tests/table/test_init.py (two entries 10 seconds out of order, plus a tie; fails on main, passes here). tests/table/test_init.py and tests/table/test_inspect.py pass.Are there any user-facing changes?
Time travel by timestamp returns the right snapshot when the snapshot log has entries slightly out of timestamp order.