Skip to main content

Snapshot Interface

The Snapshot interface represents a snapshot of the data in an Apache Iceberg table at a specific point in time. Package: org.apache.iceberg

Overview

A snapshot consists of one or more file manifests, and the complete table contents is the union of all data files in those manifests. Snapshots are created by table operations like:
  • AppendFiles - Adding new data
  • RewriteFiles - Replacing existing files
  • OverwriteFiles - Overwriting by filter
  • DeleteFiles - Removing files
  • RowDelta - Row-level changes
Snapshots enable time travel queries and provide ACID guarantees through immutable metadata.

Identity and Metadata

snapshotId()

Returns this snapshot’s unique ID. Returns: A long snapshot ID Example:

sequenceNumber()

Returns this snapshot’s sequence number. Sequence numbers are assigned when a snapshot is committed and increase monotonically. Returns: A long sequence number

parentId()

Returns this snapshot’s parent snapshot ID, or null if this is the first snapshot. Returns: The parent snapshot ID, or null Example:

timestampMillis()

Returns this snapshot’s timestamp in milliseconds. This timestamp is the same as those produced by System.currentTimeMillis(). Returns: A long timestamp in milliseconds since epoch Example:

schemaId()

Returns the ID of the schema used when this snapshot was created. Returns: The schema ID, or null if not available

manifestListLocation()

Returns the location of this snapshot’s manifest list. Returns: The manifest list file location, or null if not separate

Operation Information

operation()

Returns the name of the data operation that produced this snapshot. Returns: The operation name (e.g., “append”, “overwrite”, “delete”), or null if unknown Common Operations:
  • append - New data appended
  • overwrite - Data overwritten
  • delete - Data deleted
  • replace - Partitions replaced
Example:

summary()

Returns a string map of summary data for the operation that produced this snapshot. Summary data typically includes:
  • added-data-files - Number of data files added
  • deleted-data-files - Number of data files deleted
  • added-records - Number of records added
  • deleted-records - Number of records deleted
  • total-data-files - Total data files after operation
  • total-records - Total records after operation
Returns: A map of summary key-value pairs Example:

Manifest Access

allManifests(FileIO io)

Returns all manifest files (both data and delete manifests) in this snapshot.
FileIO
required
A FileIO instance used for reading files from storage
Returns: List of ManifestFile objects Example:

dataManifests(FileIO io)

Returns manifest files for data files only.
FileIO
required
A FileIO instance used for reading files from storage
Returns: List of data ManifestFile objects Example:

deleteManifests(FileIO io)

Returns manifest files for delete files only.
FileIO
required
A FileIO instance used for reading files from storage
Returns: List of delete ManifestFile objects

Data File Access

addedDataFiles(FileIO io)

Returns all data files added to the table in this snapshot. The files include these columns:
  • file_path
  • file_format
  • partition
  • record_count
  • file_size_in_bytes
  • Data and file sequence numbers
FileIO
required
A FileIO instance used for reading files from storage
Returns: Iterable of DataFile objects added in this snapshot Example:

removedDataFiles(FileIO io)

Returns all data files removed from the table in this snapshot.
FileIO
required
A FileIO instance used for reading files from storage
Returns: Iterable of DataFile objects removed in this snapshot Example:

Delete File Access

addedDeleteFiles(FileIO io)

Returns all delete files added to the table in this snapshot. The files include these columns:
  • file_path
  • file_format
  • partition
  • record_count
  • file_size_in_bytes
FileIO
required
A FileIO instance used for reading files from storage
Returns: Iterable of DeleteFile objects added in this snapshot Throws: UnsupportedOperationException if not implemented

removedDeleteFiles(FileIO io)

Returns all delete files removed from the table in this snapshot.
FileIO
required
A FileIO instance used for reading files from storage
Returns: Iterable of DeleteFile objects removed in this snapshot Throws: UnsupportedOperationException if not implemented

Row Lineage (Optional)

firstRowId()

Returns the row-id of the first newly added row in this snapshot. All rows added in this snapshot will have a row-id greater than or equal to this value. Returns: The first row-id used in this snapshot, or null when row lineage is not supported

addedRows()

Returns the upper bound of the number of rows with assigned row IDs in this snapshot. This can be used to safely increment the table’s next-row-id during a commit. The value may be more than the number of rows added in this snapshot and can include some existing rows. Returns: The upper bound of rows with assigned row IDs, or null if not stored
This field is optional but required when the table version supports row lineage.

Encryption

keyId()

Returns the ID of the encryption key used to encrypt this snapshot’s manifest list. Returns: A string key ID, or null if not encrypted

Usage Examples

Getting Current Snapshot

Examining Snapshot Summary

Listing Manifests

Inspecting Added and Removed Files

Traversing Snapshot History

Time Travel with Snapshots

Examining Snapshot Lineage

Getting Snapshot by Reference

Analyzing Delete Files

Best Practices

Snapshot Management:
  • Regularly expire old snapshots to reduce metadata overhead
  • Use snapshot references for important table states
  • Leverage time travel for auditing and debugging
  • Monitor snapshot growth to manage storage costs
Performance Considerations:
  • Accessing file lists from snapshots can be expensive for large tables
  • Use snapshot summary data when possible instead of iterating files
  • Consider snapshot expiration policies based on retention requirements

Source Code Reference

Source: org/apache/iceberg/Snapshot.java:34