Iceberg Partition Evolution: Change Layouts Without Rewrites
Iceberg partition evolution changes table metadata only: old files keep their spec, new writes use the new one, and queries plan across both. No rewrites.
Iceberg partition evolution is a metadata-only operation: the table commits a new partition spec, existing data files keep the spec they were written under, and new writes use the new layout. Queries then plan across every spec present. Nothing is rewritten automatically, and no performance gain is guaranteed. This guide takes the current Apache Iceberg documentation as its reference; all SQL below is illustrative, unexecuted, and must be validated against the Iceberg and Spark versions you actually run.
What Does Iceberg Partition Evolution Actually Change?
It is a metadata operation: the ALTER itself rewrites no data files. The commit adds a new partition spec object to the table's partition-specs list and moves default-spec-id to point at it, while the previous spec stays in the list. The Iceberg table spec describes partition-specs as a list of full spec objects and default-spec-id as the ID of the current spec that writers use by default; last-partition-id tracks the highest field ID across all specs so evolved fields never collide. The evolution page states the operational consequence plainly: partition evolution is a metadata operation and does not eagerly rewrite files.
What physically changes is the metadata JSON (a new version file under the table's metadata directory) and, on the next write, the manifest list and manifests that record the new files. What stays untouched is the data itself: every existing Parquet or Avro file, and the manifest entries that reference them, keep the spec ID they were written with. A partition spec change is therefore cheap in I/O terms — it costs a metadata commit, not a table scan — but it also means the old layout persists in the table until something explicitly replaces those files.
One practical precondition: in Spark, partition evolution DDL is not available in the base Iceberg integration. The Spark DDL page groups ADD, DROP and REPLACE PARTITION FIELD under SQL extensions that are available when Iceberg SQL extensions are enabled, and the same page warns that Hive Metastore schema validation can reject column changes that shift column positions. Confirm both before you plan a change.
Why Can One Table Hold Files From Several Partition Specs?
Because spec identity travels with the data, not with the table. The partition spec is recorded once per manifest rather than per file: the Iceberg table spec stores partition_spec_id in the manifest list entry, and the manifest file's key-value metadata carries partition-spec-id, while a manifest entry itself holds only status, snapshot_id, sequence_number, file_sequence_number and data_file — its partition tuple, not the spec ID. The manifest list entry also stores partition field summaries for that manifest under its spec. The table metadata keeps every partition version separately, so a reader can interpret a file written in 2026 under a day transform and a file written in 2027 under an hour transform without ambiguity. Convenience comes from Spark's read layer rather than the file format: the Spark queries page shows the files metadata table exposing a spec_id column per file, and the manifests table exposing partition_spec_id per manifest.
The canonical illustration on the evolution page is a table partitioned by month for 2008 data and then updated to partition by day from 2009 onward; both layouts coexist in the same table. Nothing about the 2008 files changes when the 2009 spec is committed.
The reason queries survive this is hidden partitioning. Iceberg derives partition values from source columns, so you filter on event_time, not on a partition column, and the engine prunes files automatically. A query does not need to know which spec a file belongs to — the planner does that resolution per layout. That is also why the Iceberg versus Delta Lake comparison of delete semantics and auditability is worth reading alongside this: spec IDs and sequence numbers are the audit trail that makes multi-spec tables explainable after the fact. If you're still weighing layout choices, the guide to partitioning versus sorting for pruning covers when a new partition spec is the right lever at all. For more on versioned contracts, rollback and replay across lakehouse layers, see the guide to medallion architecture schema evolution.
Before and After: What Changes When You Evolve a Partition Spec
The table below contrasts a table before and after a single spec evolution. Every cell describes documented metadata behavior; none of it implies a performance outcome.
Dimension | Before evolution (spec 0) | After evolution (spec 1) |
|---|---|---|
Active partition spec | Original fields, e.g. days(event_time) | New fields, e.g. days(event_time) plus hours(event_time) |
Spec ID recorded in metadata | 0 | 1 (spec 0 is retained, not deleted) |
Existing data files | Written under spec 0 | Unchanged; still tagged spec_id = 0 |
New writes | n/a | Written under spec 1 in the new layout |
Query planning | Single layout, one derived filter | Split planning: each layout plans its files with the filter derived for that spec |
Data rewrite required | n/a | None for the ALTER itself; old files keep the old layout until explicitly rewritten |
Performance outcome | n/a | Not guaranteed; depends on query filters, file sizes, and manifest layout |
How Do You Evolve a Partition Spec in Spark SQL?
Work through the steps in order against a configured Iceberg catalog, checking metadata after each change. The fixture below uses a Hadoop-typed catalog for portability; substitute your production catalog type and warehouse path.
Step 1: Start Spark with the Iceberg extensions on the classpath
Partition-evolution DDL lives in the Iceberg SQL extensions, not in the base Spark integration. The Spark DDL page puts ADD, DROP and REPLACE PARTITION FIELD under "ALTER TABLE SQL extensions", which are "available in Spark 3 when using Iceberg SQL extensions". The Spark configuration page lists that extension as org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions and documents catalog properties nested under the catalog name (type, warehouse).
Runtime SET spark.sql.extensions=... can't be relied on here. The extension class has to be on the classpath and the session has to resolve it while it initializes, so treat it as a launch-time setting rather than a statement you run at the top of a script.
# Example launch command — validate in your target environment.
spark-sql \
--packages org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:<compatible-version-placeholder> \
--conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
--conf spark.sql.catalog.local=org.apache.iceberg.spark.SparkCatalog \
--conf spark.sql.catalog.local.type=hadoop \
--conf spark.sql.catalog.local.warehouse=/tmp/iceberg-warehouse
The artifact coordinate is not fixed. You must choose the runtime JAR that matches your Spark minor version and Scala binary version, and whose Iceberg release is the one you intend to run — iceberg-spark-runtime-3.5_2.12 targets Spark 3.5 built against Scala 2.12, and other combinations ship under different coordinates. Substitute the version that matches your installed Spark and Iceberg, rather than copying a number from here. Confirm the extensions are active before continuing: if the launch flags were ignored, Step 4 fails with a parse error on the partition-field syntax.
That is a selection task, not a copy-paste one, and it comes first for a reason: a mismatched artifact fails at startup with a linkage or class-not-found error, not with a helpful message. Check the coordinate against the artifact table in the Apache Iceberg releases and downloads page for your exact Spark and Scala build.
Step 2: Create the namespace and the illustrative fixture table
With the catalog registered, create the namespace the fixture lives in, then a day-partitioned table, and load rows across two days so the before/after comparison has data on both sides of the ALTER.
Example configuration — validate in your target environment.
-- Example configuration — validate in your target environment.
CREATE NAMESPACE IF NOT EXISTS local.db;
CREATE TABLE local.db.events (
event_id BIGINT,
user_id BIGINT,
event_time TIMESTAMP,
payload STRING
)
USING iceberg
PARTITIONED BY (days(event_time));
INSERT INTO local.db.events VALUES
(1, 1001, TIMESTAMP '2026-11-01 10:15:00', 'a'),
(2, 1002, TIMESTAMP '2026-11-01 11:45:00', 'b'),
(3, 1001, TIMESTAMP '2026-11-02 09:05:00', 'c');
Expected observation (unexecuted): three rows land in two day partitions under spec ID 0.
Step 3: Record a baseline from the files metadata table
There is no specs metadata table to query. The Spark queries page documents the metadata tables that actually exist, and none of them is called specs: the spec information surfaces through columns instead — spec_id on files, partitions and position_deletes, and partition_spec_id on manifests. A statement like SELECT * FROM local.db.events.specs has nothing to read.
What you can write down is which files carry which spec. The files table exposes file_path, spec_id, partition, record_count and file_size_in_bytes, which is enough for a baseline.
-- Example configuration — validate in your target environment.
SELECT spec_id, file_path
FROM local.db.events.files
ORDER BY file_path;
Expected observation (unexecuted): every row shows the current spec ID — 0 in this fixture — because no other spec exists yet. Save the paths. When you repeat this query later, the same paths must reappear with the same spec_id.
One caveat that trips people up: you cannot confirm a new partition spec from the files table until a write lands under it, because that table reports specs through data files. Immediately after the ALTER, this query returns exactly what it returned before, and that's expected rather than a bug. The order is alter, insert, then compare.
Step 4: Replace the partition field in one metadata update
The documented statement for swapping a layout is REPLACE PARTITION FIELD ... WITH, which the Spark DDL page introduces as replacing one partition field with a new one "in a single metadata update":
ALTER TABLE prod.db.sample REPLACE PARTITION FIELD ts_day WITH day(ts);
The same form applies to a transform on a source column, so swapping the day transform for an hour transform looks like this:
-- Example configuration — validate in your target environment.
ALTER TABLE local.db.events
REPLACE PARTITION FIELD days(event_time) WITH hours(event_time);
SELECT spec_id, file_path
FROM local.db.events.files
ORDER BY file_path;
Expected observation (unexecuted): the same rows as your Step 3 baseline — same paths, same spec_id = 0. Nothing was rewritten and no new spec is visible yet.
Two warnings from the same page are worth carrying into your runbook. Sequentially adding then dropping a partition field commits two specs and leaves an intermediate layout behind, which is why the single replace form is the better default. And dropping a partition field changes the schema of metadata tables, which can break metadata queries or make their results look different; keeping the old field around is the safer route when you still need to read history under the old layout.
Step 5: Insert after the ALTER and confirm split specs
This is the core verification. New files carry the new spec ID, old files keep theirs, and the ALTER itself rewrote nothing.
-- Example configuration — validate in your target environment.
INSERT INTO local.db.events VALUES
(4, 1003, TIMESTAMP '2026-11-03 14:20:00', 'd');
SELECT spec_id, COUNT(*) AS file_count
FROM local.db.events.files
GROUP BY spec_id
ORDER BY spec_id;
Expected observation (unexecuted): two groups instead of one — the original spec ID with its original files, and a new spec ID, typically 1, with the file or files that insert produced. The exact counts depend on your engine version, write parallelism and row-group sizing, so compare which paths sit in which group against your baseline instead of comparing numbers to this article. A path that appears under a different spec_id than before means something rewrote it, and the ALTER alone should never do that.
How Does Query Planning Work Across Multiple Specs?
Split planning is the mechanism. For each partition layout present in the table, the planner derives a filter specific to that layout and prunes files against it. The evolution page describes this directly: each partition layout plans files separately using the filter it derives for that specific partition layout.
In the fixture above, a query filtering event_time between two hours produces a day-granularity predicate for spec 0 files and an hour-granularity predicate for spec 1 files. Both are correct; they differ in how much they can prune. A spec 0 file covering a whole day must be opened even if only one hour matches, because the file's partition summary cannot narrow below the day. That is a consequence of the old layout's granularity, not a defect introduced by the evolution.
Hidden partitioning is what makes this transparent to query authors. Because Iceberg derives partition values from source columns, you write ordinary predicates on event_time and the engine handles spec resolution. The Spark queries page also documents transform functions that let you inspect how Iceberg computes partition values, which is useful when validating that a filter actually aligns with a spec.
Two planning-side costs deserve attention. First, more specs means more manifests to scan during planning, so a table that accumulates many specs over years carries more planning metadata. Second, manifest layout matters independently of spec count; the maintenance page notes that manifests are automatically compacted in the order they are added, and that rewriting manifests helps when write patterns do not align with query patterns.
Does Partition Evolution Rewrite Data or Guarantee Faster Queries?
No on both counts. Partition evolution is a metadata operation and does not eagerly rewrite files, per the evolution page. There is no documented performance guarantee attached to it, and the documentation does not promise that a finer layout makes any particular query faster.
What actually determines whether a query benefits is whether your filters align with the new layout, how large the files are, and how the manifests are organized. A table that moves from day to hour partitioning helps queries that filter to sub-day ranges on newly written data; it does nothing for the historical files still sitting in day partitions. Those files keep the old layout until something explicitly replaces them.
This is why the honest framing is a trade-off, not an upgrade. You gain a layout that fits current access patterns for future writes, at the cost of a table that now carries two layouts and two sets of planning metadata. If your workload is dominated by scans of historical data, evolving the spec changes little until you also rewrite that history.
Measure before and after in your own environment rather than assuming an outcome. Compare scan planning time, files opened per query, and bytes read for representative predicates — those are the quantities the layout actually influences.
Compaction vs. a Deliberate Layout Rewrite: What Is the Difference?
These are four distinct operations, and conflating them is the most common source of confusion about partition evolution.
Partition evolution changes metadata only. No data file is read or written. It affects future writes.
Compaction via rewrite_data_files rewrites data files, primarily to combine small files and reduce metadata overhead and file-open cost. The maintenance page describes this as combining small files into larger files. The Spark procedures page documents the options, including target-file-size-bytes (default 536870912, i.e. 512 MB), min-input-files (default 5), and output-spec-id, which defaults to the current partition spec ID and causes data to be reorganized during the rewrite to align with the output partitioning. That output-spec-id option is a practical bridge between evolution and migration: a compaction can move old files into the new layout.
Manifest rewriting via rewrite_manifests regroups data files into manifests to improve planning. It does not rewrite data files. The maintenance page frames it as the remedy when a table's write pattern does not align with its query pattern.
A deliberate layout rewrite is the planned, explicit migration of historical files to the new spec — typically a scoped rewrite_data_files run with output-spec-id set, executed in batches with capacity planning. Rewriting old files in this way is how they adopt the new layout.
For a table where small-file pressure and layout drift arrive together, a single scoped rewrite can address both. Where only planning is slow, manifest rewriting is the cheaper lever. If compaction is your actual trigger rather than layout drift, the measurement approach in small-files compaction and streaming latency is a better starting point. Either way, validate the procedure against your own catalog and engine version before scheduling it.
What Should You Verify After Evolving a Partition Spec?
Run this checklist against the table after the ALTER and again after the first post-evolution write. Most items need that write to be meaningful — the files table can only show you specs that files exist under.
Old specs are retained, and the replace produced exactly one new one. You can't read a spec catalog from SQL, so verify it indirectly: before the ALTER, save the distinct
spec_idvalues infiles. After the first post-evolution insert, a secondspec_idshould appear and no earlier one should disappear.Old files still carry their original
spec_id. Group thefilestable byspec_idand compare against your pre-change baseline. Every path recorded earlier should still sit under the spec it had, with its row count intact.New writes carry the new
spec_id. After inserting post-evolution rows, confirm aspec_idgroup appears that didn't exist in your baseline, and that the new rows are in it.No data files were rewritten by the ALTER. Compare file paths, not just counts. A metadata-only change leaves every pre-existing path intact — and the query you ran straight after the ALTER, before the insert, already proves it.
Queries filtering on source columns return correct results across specs. Run predicates that hit both old and new layouts and reconcile row counts against a known total. Correctness matters more than speed here.
Manifest counts and planning behavior match expectations. Inspect the
manifeststable forpartition_spec_iddistribution; a jump in manifests per spec is a planning cost worth tracking.Maintenance is scheduled separately. Compaction and manifest rewriting are independent jobs with their own cadence; neither happens because you evolved a spec.
Keep the baseline output from before the change. Without it, step 4 becomes an assertion rather than a check.
Frequently Asked Questions
Does changing an Iceberg partition spec rewrite existing data files?
No. It is a metadata operation that does not eagerly rewrite files. Existing data files keep their original spec and layout until an explicit rewrite or a compaction that targets a new output spec.
Can one Iceberg table contain files written under different partition specs at the same time?
Yes. Files written under different partition specs can coexist. The spec ID is associated with each manifest (in the manifest list entry and manifest metadata), and readers plan each layout using its corresponding spec.
Do I need the Iceberg SQL extensions to run ALTER TABLE partition-field statements in Spark?
Yes. The Spark DDL page groups ADD, DROP and REPLACE PARTITION FIELD under Iceberg SQL extensions, which must be present on the classpath and registered when the Spark session starts — a runtime SET spark.sql.extensions is not a reliable way to enable them. The same page describes a Hive catalog limitation around schema changes.
Is partition evolution the same as compaction?
No. Compaction with rewrite_data_files rewrites data files to merge small files and can align output to a chosen spec. rewrite_manifests regroups manifests without rewriting data. Partition evolution only changes metadata for future writes.
Will evolving my partition spec make my queries faster?
No documented performance guarantee. Any gain depends on how well query filters align with the new layout, file sizes, and manifest layout, and old files keep the old layout until explicitly rewritten. Validate in your own environment.