≈ The Lake

Part 6 · Interoperability · Chapter 22

Delta and Iceberg: comparison and interoperability

The two protocols side by side, and the ways to serve one copy of data to both: the IcebergCompat table features, Delta UniForm's commit-by-commit conversion to Iceberg, and Apache XTable.

complete ~25 min

After this chapter you should be able to:
  • Map each Delta concept to its Iceberg counterpart and note where they differ.
  • Explain what IcebergCompat requires of a Delta writer and why.
  • Predict which Iceberg snapshot UniForm writes for a given Delta commit.

Parts 4 and 5 described Delta and Iceberg separately. Both store data in Parquet files on object storage and describe the table in metadata files beside them, so the question this chapter answers is how close they are, and whether one copy of the data files can be read as both. The answer is yes, under conditions: the IcebergCompat table features constrain how a Delta writer lays out its files, and Delta UniForm writes Iceberg metadata for every Delta commit over the same Parquet files.

The simulator in src/sim/delta/uniform.ts ports the compat checks and the converter’s decision table from Delta’s source at the pin, and its tests pin the Iceberg operation produced for each kind of Delta commit.

Concept map

DeltaIceberg
Table stateReplay of the log _delta_log/N.json from the last checkpoint (chapter 9)A tree: table metadata → snapshot → manifest list → manifests (chapter 16)
VersionLog version N, a dense integerSnapshot id, plus a sequence number that orders snapshots
Commit pointCreating N.json with put-if-absent, or the catalog ratifying it for catalog-managed tables (chapters 10, 14)The catalog swapping the table’s current metadata location (chapter 17)
File statsstats JSON in each add actiondata_file fields in manifest entries; per-partition summaries in the manifest list
PartitioningIdentity on columns; values in partitionValues, not in the filesTransforms (bucket, truncate, day, …) with partition evolution (chapter 18)
SchemaSpark-style JSON; column mapping adds ids and physical names (chapter 15)Field ids are mandatory; schemas evolve by id (chapter 19)
Row-level deletesDeletion vectors (chapter 13)Position and equality delete files in v2, deletion vectors in v3 (chapter 20)
MaintenanceOPTIMIZE, VACUUMRewrite data files, expire snapshots, remove orphans

The two models converge in what they record and differ in how it is organized. Delta’s log is a sequence of deltas that must be replayed (or read from a checkpoint) to get the file list. Iceberg’s tree is a materialized file list per snapshot, with manifests shared between snapshots. Both put column statistics in metadata so planning can prune without opening files, and both need an atomic primitive to commit.

Quiz Check: the concept mapAnswers are scheduled for spaced review on the Review page.

Q1. What is the commit point in each format?

How sure are you?

Q2. Where does each format keep per-file column statistics?

How sure are you?

IcebergCompat: what a Delta writer must do

For an Iceberg reader to read a Delta table’s Parquet files directly, the files have to look like files an Iceberg writer would produce. PROTOCOL.md defines two writer features for this, icebergCompatV1 and icebergCompatV2. It says each “ensures that Delta tables can be converted to Apache Iceberg™ format, though this table feature does not implement or specify that conversion.”[PROTOCOL.md: Iceberg Compatibility V1] The requirements, and the Iceberg rule each one serves:

  • Column mapping in name or id mode. Iceberg resolves Parquet columns by field id, not name, so Delta’s column mapping supplies the ids and writes them into the files. V2 also gives ids to array elements and map keys and values, in a delta.columnMapping.nested.ids map, and writes them as Parquet field_ids.[PROTOCOL.md: Iceberg Compatibility V2]
  • Partition values materialized into the data files. Delta keeps partition values in the log. The Iceberg spec says “All columns must be written to data files even if they introduce redundancy with metadata stored in manifest files (e.g. columns with identity partition transforms).”[Iceberg spec: Writing data files]
  • numRecords in every AddFile’s stats. record_count is a required field of an Iceberg data_file, and a converter should not open files to count rows.[Iceberg spec: Manifests]
  • No deletion vectors in V1 and V2, which target Iceberg v2, whose deletes are separate delete files.
  • Types Iceberg has. V1 blocks Map, Array and Void; V2 has an explicit allow-list (byte to struct, with timestampNTZ) and requires timestamps as int64. Type widening is allowed only for changes Iceberg’s schema evolution also allows.
  • No renaming of partition columns on replace, so the Iceberg partition spec stays valid.

The source at the pin goes one step further than the spec. IcebergCompat.scala defines IcebergCompatV3 with icebergFormatVersion = 3: it requires row tracking, allows the variant type, and does not list deletion vectors as incompatible, because Iceberg v3 has its own deletion vectors and row lineage.[IcebergCompat.scala] V3 is not in PROTOCOL.md at the pin, so it is implementation behavior.

Quiz Check: IcebergCompatAnswers are scheduled for spaced review on the Review page.

Q1. Why do IcebergCompatV1 and V2 require column mapping in name or id mode?

How sure are you?

Q2. Why must every AddFile carry numRecords under IcebergCompat?

How sure are you?

Q3. Delta normally leaves partition columns out of Parquet files. Why must an IcebergCompat writer write them?

How sure are you?

Q4. A Delta table has deletion vectors. Which IcebergCompat version can it use at the pinned Delta commit?

How sure are you?

How UniForm converts a commit

UniForm (Universal Format) is the part of Delta that writes the Iceberg metadata. It is enabled with delta.universalFormat.enabledFormats = iceberg on a table that has an IcebergCompat version. The data files are not copied: the Iceberg manifests point at the same Parquet files the Delta log does, which is why the compat rules above exist.

When it runs. At the pinned commit the converter’s old post-commit entry points (enqueueSnapshotForConversion, convertSnapshot) throw “no longer supported”.[IcebergConverter] Conversion runs before the Delta commit instead: OptimisticTransaction calls convertUncommitedTxn for a catalog table with UniForm enabled, writes the Iceberg metadata for the attempt version, and records its location in the transaction before committing.[OptimisticTransaction: generateIcebergAndUpdateCurrentTransactionInfo][IcebergConverter.convertUncommitedTxn] The Iceberg metadata therefore exists by the time the Delta version does.

Two metadata views lead to the same files
Delta reader
  1. Delta transaction log Replay file actions to choose the snapshot’s Parquet paths.
Iceberg reader
  1. Converted metadata Traverse the manifest list and manifests to choose Parquet paths.
Shared Parquet files Both metadata views reference the same data objects.
At the pinned version, the converter produces the Iceberg metadata before the Delta commit.[Delta converter call]

What it writes. convertSnapshotInternal first decides how much to convert. The Iceberg table’s properties record the last converted Delta version (delta-version) and its timestamp.[IcebergConverter properties] If there is no Iceberg table yet, it is CREATE_TABLE. If the last converted snapshot can be loaded (the gap is at most iceberg.maxPendingCommits, default 100, and its log file still exists), it is WRITE_TABLE, and each pending Delta commit becomes its own Iceberg snapshot. Otherwise it is REPLACE_TABLE, built from every live AddFile.[convertSnapshotInternal][DeltaSQLConf: iceberg.maxPendingCommits]

For each Delta commit, runIcebergConversionForActions reads the adds, the removes, whether they change data, and whether any carries a DV, and picks an Iceberg pending update:[runIcebergConversionForActions]

// IcebergConverter.runIcebergConversionForActions (trimmed)
(addFiles.nonEmpty, removeFiles.nonEmpty, dataChange) match {
  case (true, false, DataChange.All) if !hasDv  => icebergTxn.getAppendOnlyHelper  // newAppend()
  case (true, false, DataChange.All) if hasDv   => icebergTxn.getRowDeltaHelper
  case (true, false, DataChange.None)           => icebergTxn.getNullHelper      // ignore
  case (false, true, _) if hasDv                => icebergTxn.getRowDeltaHelper
  case (false, true, _)                         => icebergTxn.getRemoveOnlyHelper // newDelete()
  case (true, true, DataChange.All) if hasDv    => icebergTxn.getRowDeltaHelper
  case (true, true, DataChange.None) if hasDv   =>   // OPTIMIZE over files with DVs
    if (addedDvCardinality <= removedDvCardinality) icebergTxn.getRewriteHelper
    else icebergTxn.getRowDeltaHelper
  case (true, true, DataChange.All) if !hasDv   => icebergTxn.getOverwriteHelper  // newOverwrite()
  case (true, true, DataChange.None) if !hasDv  => icebergTxn.getRewriteHelper    // newRewrite()
  case (false, false, _)                        => icebergTxn.getNullHelper
  case _ => throw new UnsupportedOperationException(
    "Unsupported combination of actions for incremental conversion.")
}
removeFiles.foreach(txnHelper.add)
addFiles.foreach(txnHelper.add)
txnHelper.commit(deltaVersion)   // the snapshot's sequence number is the Delta version

dataChange comes from the commit’s recorded value, and the converter throws if it disagrees with the file actions. A commit that mixes data-changing and non-data-changing file actions has no case and fails the conversion. Each helper wraps one Iceberg API: AppendFiles, DeleteFiles, OverwriteFiles, RewriteFiles or RowDelta.[IcebergConversionTransaction helpers] The snapshot’s operation then comes from Iceberg: RewriteFiles is always replace; OverwriteFiles and RowDelta report append or delete when they only add or only remove, and overwrite otherwise.[BaseOverwriteFiles.operation][BaseRowDelta.operation]

A few details follow from the table:

  • OPTIMIZE is a replace, so Iceberg readers and Iceberg incremental reads (chapter 35) skip it as they skip native compaction. Converting an OPTIMIZE also triggers Iceberg snapshot expiration.
  • A DV change is a RowDelta. Delta changes a file’s DV by removing the AddFile and adding it back with the new DV. The row-delta helper pairs those by path and writes only the delete-file change, because Iceberg’s RowDelta cannot delete a data file while adding a delete file for it.[RowDeltaHelper]
  • A rebased OPTIMIZE can add more masked rows than it removes, when a concurrent DELETE hit one of its inputs. RewriteFiles rejects more records added than replaced, so the converter compares DV cardinalities and uses RowDelta in that case.
  • COMPUTE STATS and metadata-only commits produce no snapshot.
Quiz Check: conversionAnswers are scheduled for spaced review on the Review page.

Q1. A Delta OPTIMIZE commit (removes and adds, dataChange = false, no DVs) is converted. Which Iceberg operation results?

How sure are you?

Q2. How does a reader tell which Delta version an Iceberg snapshot of a UniForm table corresponds to?

How sure are you?

Q3. The last conversion was at Delta version 10 and the table is now at version 150. What does the converter do?

How sure are you?

Apache XTable

Apache XTable (incubating) solves the same problem from outside the writer. It is a separate process that reads the metadata of a source table (Delta, Iceberg or Hudi) into a format-neutral InternalTable and snapshot model, then writes metadata for each target format over the same data files.[XTable InternalTable]

ConversionController.syncTableFormats decides per target. Each target records the last source instant it synced. If the target says incremental sync is safe and the source confirms it can produce changes from that instant, XTable extracts the table changes since then and applies them; otherwise it extracts a full snapshot and syncs that.[XTable ConversionController] It is the same create, incremental or replace decision UniForm makes, run on a schedule rather than inside each commit, so the target metadata lags the source by up to one sync interval.

The trade-off between the two: UniForm keeps Iceberg metadata in step with every Delta commit, at the cost of conversion work on the commit path and the IcebergCompat restrictions on the writer. XTable leaves writers untouched and works between any pair of formats, but readers of the target see the table only as of the last sync, and the source files still have to be readable by the target’s readers.

Quiz Check: XTableAnswers are scheduled for spaced review on the Review page.

Q1. How does Apache XTable differ from UniForm?

How sure are you?

Try it

  • Conversion. With no previous conversion, convert up to version 5: one CREATE_TABLE snapshot holding every live file. Set the last converted version to 1: each commit becomes its own snapshot (append, overwrite, delete, replace), version 5’s COMPUTE STATS is skipped, and the OPTIMIZE triggers expiration. Tick “log file is gone” to force REPLACE_TABLE.
  • Deletion vectors. Turn them on: the DELETE becomes a RowDelta recorded as delete, the UPDATE an overwrite, and the OPTIMIZE over files with DVs stays a replace.
  • IcebergCompat checks. Start from the default (no column mapping, DVs on) and fix the table until V2 accepts it, then switch to V3 and see what it needs instead.

Table operation: CREATE_TABLE (no Iceberg table yet: one snapshot with every live file). Table property delta-version = 5.

Delta _delta_log
  1. CREATE TABLE AS SELECT +f1.parquet+f2.parquet
  2. WRITE (append) +f3.parquet
  3. UPDATE −f2.parquet+f4.parquet
  4. DELETE −f1.parquet
  5. OPTIMIZE −f3.parquet−f4.parquet+f5.parquet
  6. COMPUTE STATS
Iceberg snapshots written
seqoperationdata files after
5append
txn.newAppend() → AppendFiles
f5.parquet

Summary

  • Delta and Iceberg record the same things (files, stats, schema, partition values, deletes) in different structures: a replayed log versus a tree of manifests. Both commit with one atomic step.
  • icebergCompatV1 and V2 make a Delta writer produce files an Iceberg reader can use: column mapping for field ids, materialized partition columns, numRecords stats, no DVs, and Iceberg’s types. The code’s IcebergCompatV3 targets Iceberg v3 and allows DVs with row tracking.
  • UniForm converts each Delta commit to an Iceberg snapshot over the same files, before the Delta commit at the pin, with the sequence number set to the Delta version. Appends become append, copy-on-write DML overwrite or delete, OPTIMIZE replace, DV changes RowDelta. A gap over 100 commits rebuilds the table.
  • XTable translates metadata between formats as a separate sync, incrementally when it can.

Concepts in this chapter

Explained here

See how the book's concepts connect →

Primary sources

Review this chapter

This chapter has 10 quiz questions.

Review this chapter's cards → Review all due cards