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/update/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def set_statistics(self, statistics_file: StatisticsFile) -> "UpdateStatistics":
return self

def remove_statistics(self, snapshot_id: int) -> "UpdateStatistics":
self._updates = (
self._updates += (
RemoveStatisticsUpdate(
snapshot_id=snapshot_id,
),
Expand Down
32 changes: 32 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,38 @@ def test_remove_statistics_update(table_v2_with_statistics: Table) -> None:
)


def test_update_statistics_set_then_remove_keeps_both_updates(table_v2_with_statistics: Table) -> None:
current_snapshot_id = 3055729675574597004
previous_snapshot_id = 3051729675574597004

statistics_file = StatisticsFile(
snapshot_id=current_snapshot_id,
statistics_path="s3://bucket/warehouse/new-stats.puffin",
file_size_in_bytes=124,
file_footer_size_in_bytes=27,
blob_metadata=[
BlobMetadata(
type="apache-datasketches-theta-v1",
snapshot_id=current_snapshot_id,
sequence_number=2,
fields=[1],
)
],
)

# The fixture already has statistics for both snapshots
assert {stats.snapshot_id for stats in table_v2_with_statistics.metadata.statistics} == {
current_snapshot_id,
previous_snapshot_id,
}

transaction = table_v2_with_statistics.transaction()
transaction.update_statistics().set_statistics(statistics_file).remove_statistics(previous_snapshot_id).commit()

# set_statistics replaces the current snapshot's statistics, remove_statistics drops the previous one
assert transaction.table_metadata.statistics == [statistics_file]


def test_set_partition_statistics_update(table_v2_with_statistics: Table) -> None:
snapshot_id = table_v2_with_statistics.metadata.current_snapshot_id

Expand Down
Loading