Time Travel Queries in Apache Iceberg

·
Data Engineering Apache Iceberg SQL

Discovered today that Apache Iceberg makes time travel queries incredibly simple. This is a game-changer for debugging data pipelines.

Query as of a Timestamp

SELECT * FROM catalog.db.table
FOR SYSTEM_TIME AS OF TIMESTAMP '2025-03-07 10:00:00'

Query a Specific Snapshot

SELECT * FROM catalog.db.table
FOR SYSTEM_VERSION AS OF 123456789

Why This Matters

  1. Debugging - Reproduce issues by querying data as it existed when the bug occurred
  2. Auditing - See what data looked like at any point in time
  3. Recovery - Easily rollback to a previous state if something goes wrong

Pro Tip

Combine with DESCRIBE HISTORY to see all available snapshots:

DESCRIBE HISTORY catalog.db.table

This shows snapshot IDs, timestamps, and what operation created each snapshot.