Skip to content

Commit 11120bf

Browse files
committed
fixup! Add table statistics update
1 parent d3aaab3 commit 11120bf

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

mkdocs/docs/api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,16 @@ table.update_statistics().set_statistics(snapshot_id, statistics_file).commit()
11401140
table.update_statistics()
11411141
.set_statistics(snapshot_id1, statistics_file1)
11421142
.remove_statistics(snapshot_id2)
1143+
.commit()
11431144
# Operations are applied on commit.
11441145
```
11451146

11461147
You can also use context managers to make more changes:
11471148

11481149
```python
11491150
with table.update_statistics() as update:
1150-
update.set_statistics(1, statistics_file)
1151-
update.remove_statistics(2)
1151+
update.set_statistics(snaphsot_id1, statistics_file)
1152+
update.remove_statistics(snapshot_id2)
11521153
```
11531154

11541155
## Query the data

pyiceberg/table/statistics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class StatisticsFile(IcebergBaseModel):
4242
blob_metadata: List[BlobMetadata] = Field(alias="blob-metadata")
4343

4444

45-
def reject_statistics(
45+
def filter_statistics_by_snapshot_id(
4646
statistics: List[StatisticsFile],
4747
reject_snapshot_id: int,
4848
) -> List[StatisticsFile]:

pyiceberg/table/update/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
SnapshotLogEntry,
3838
)
3939
from pyiceberg.table.sorting import SortOrder
40-
from pyiceberg.table.statistics import StatisticsFile, reject_statistics
40+
from pyiceberg.table.statistics import StatisticsFile, filter_statistics_by_snapshot_id
4141
from pyiceberg.typedef import (
4242
IcebergBaseModel,
4343
Properties,
@@ -496,7 +496,7 @@ def _(update: SetStatisticsUpdate, base_metadata: TableMetadata, context: _Table
496496
if update.snapshot_id != update.statistics.snapshot_id:
497497
raise ValueError("Snapshot id in statistics does not match the snapshot id in the update")
498498

499-
statistics = reject_statistics(base_metadata.statistics, update.snapshot_id)
499+
statistics = filter_statistics_by_snapshot_id(base_metadata.statistics, update.snapshot_id)
500500
context.add_update(update)
501501

502502
return base_metadata.model_copy(update={"statistics": statistics + [update.statistics]})
@@ -507,7 +507,7 @@ def _(update: RemoveStatisticsUpdate, base_metadata: TableMetadata, context: _Ta
507507
if not any(stat.snapshot_id == update.snapshot_id for stat in base_metadata.statistics):
508508
raise ValueError(f"Statistics with snapshot id {update.snapshot_id} does not exist")
509509

510-
statistics = reject_statistics(base_metadata.statistics, update.snapshot_id)
510+
statistics = filter_statistics_by_snapshot_id(base_metadata.statistics, update.snapshot_id)
511511
context.add_update(update)
512512

513513
return base_metadata.model_copy(update={"statistics": statistics})

0 commit comments

Comments
 (0)