Skip to main content

Overview

To query Iceberg tables in Spark, first configure Spark catalogs. Iceberg uses Apache Spark’s DataSourceV2 API for data source implementations.

Querying with SQL

In Spark, tables use identifiers that include a catalog name:

Metadata Tables

Metadata tables use the Iceberg table name as a namespace:

Time Travel

Spark supports time travel queries using TIMESTAMP AS OF or VERSION AS OF clauses:
If a branch/tag name matches a snapshot ID, the snapshot ID takes precedence. Rename branches/tags with a prefix like snapshot-1 to avoid conflicts.

Schema Selection in Time Travel

Different time travel queries use different schemas:
Branches use the table’s current schema, while tags use the snapshot’s schema at the time the tag was created.

Querying with DataFrames

Load tables as DataFrames using spark.table:

Loading with Paths

You can load tables using different identifier formats:

Time Travel with DataFrames

Use read options for time travel:

Incremental Read

Read changes between snapshots:
Incremental reads only work with append operations. They cannot handle replace, overwrite, or delete operations. Incremental read is not supported in SQL syntax.

Inspecting Tables

Iceberg provides metadata tables to inspect table state.

History

View table history with snapshot lineage:
Rows with is_current_ancestor = false indicate rolled-back commits.

Snapshots

View all snapshots in the table:

Files

View current data and delete files:
Content Types:
  • 0 - Data files
  • 1 - Position delete files
  • 2 - Equality delete files

Manifests

View manifest files:

Partitions

View current partitions with statistics:
The partitions table shows partitions with data or delete files in the current snapshot. Delete files are not applied, so some partitions may appear even if all rows are deleted.

Entries

View manifest entries with file metadata:

Position Delete Files

View position delete records:

References

View branches and tags:

Metadata Log Entries

View metadata file history:

Metadata Tables with DataFrames

Load metadata tables using the DataFrame API:

Time Travel with Metadata Tables

Inspect metadata at specific points in time:

All Metadata Tables

Metadata tables prefixed with all_ show data across all snapshots:
The “all” metadata tables may produce more than one row per file because files can be part of multiple snapshots.

all_data_files

All data files across all snapshots

all_delete_files

All delete files across all snapshots

all_entries

All manifest entries across all snapshots

all_manifests

All manifest files across all snapshots

Next Steps

Write Data

Learn about INSERT, MERGE, and UPDATE operations

Procedures

Maintain tables with stored procedures

Configuration

Configure read options and performance tuning

Structured Streaming

Stream data with Spark Structured Streaming