A bad overwrite left 3 rows and $545. One rollback to the earlier snapshot restored 8 rows and $2,050.
python3 --version.pip install "pyarrow>=18"pip install "pyiceberg[pyarrow,sql-sqlite]>=0.12"git clone https://github.com/DayanEbrar0X/data-anatomy.ai.git cd data-anatomy.ai
python3 -m venv .venv source .venv/bin/activate
pip install -r requirements.txt # or just this lesson: pip install "pyarrow>=18" "pyiceberg[pyarrow,sql-sqlite]>=0.12"
cd data-engineering/16-apache-iceberg python3 src/iceberg.py
from lake import table, orders, total
t = table() # empty Iceberg table, local disk
t.append(orders) # snapshot 1: 8 orders
t.overwrite(orders.slice(0, 3)) # buggy job
print("now:", total(t.scan()))
good = t.snapshots()[0].snapshot_id
t.manage_snapshots().rollback_to_snapshot(
good).commit()
print("rolled back:", total(t.scan()))A folder of Parquet files can't undo a mistake. This table can. Apache Iceberg saves every write as a snapshot, and a pointer marks the current one. Make a local table, and append eight orders.
That's snapshot one. A buggy job overwrites it with three rows, and we print what's left. Undo it: roll back to snapshot one. Only the pointer moves.
Before: three rows, $545. After: all eight, $2,050. Files can't undo. Snapshots can.
Read the lesson on GitHub →