Skip to main content

Hudi Writes Apache Iceberg V3 Tables on AWS

24 min read

Teams choose the Apache Hudi storage engine for fast record-level upserts and deletes through indexes, incremental processing and automatic table services. The tables Hudi writes are rarely read by a single query engine. The same table may be queried with Trino or Amazon Athena and explored with DuckDB. Some query engines expect Apache Iceberg tables, found through a catalog such as the AWS Glue Data Catalog. Users want every query engine to read the same table, with a single copy of the data.

Apache XTable (incubating) makes a Hudi table readable as an Iceberg table through metadata conversion. Hudi and Iceberg tables both store data in Parquet files. The two formats differ in the metadata that describes the data files. After each Hudi commit, XTable reads the table's Hudi metadata and translates the Hudi metadata into Iceberg metadata, over the same data files. Query engines supporting Iceberg can then read the table. The table stays a Hudi table, and the table's Iceberg metadata comes from the metadata sync.

Hudi's Pluggable Table Format now enables Hudi's storage engine to write Iceberg tables directly. The storage engine covers Hudi's writers, indexes, concurrency control and table services. An Iceberg plugin from Apache XTable writes the Iceberg metadata as part of each Hudi commit. Every Hudi commit is also an Iceberg commit, and the table is a standard Iceberg table, at Iceberg format version 2 or 3.

Writing Iceberg from Hudi's storage engine, instead of converting metadata after each commit, brings three benefits:

  • Every transaction, right away. A conversion runs after the Hudi commit, so Iceberg readers wait for the next sync. The sync is also another job to schedule and monitor. Here a Hudi transaction completes only when the transaction's Iceberg snapshot is committed through the catalog. Iceberg readers see each transaction as soon as the transaction completes.
  • Merge-on-Read in full. Conversion translates base files only. Iceberg readers of a Merge-on-Read table see the table's read-optimized view, without the updates since the last compaction. Here Merge-on-Read updates and deletes become Iceberg deletion vectors, so Iceberg readers see the latest rows.
  • Hudi's storage engine, end to end. Hudi's indexes drive record-level upserts and deletes. Hudi runs compaction, clustering and cleaning. The result is a standard Iceberg table in the catalog, with V3 deletion vectors and row lineage. Hudi's storage engine stays in place, with no migration.

This post shows Hudi writing two Iceberg tables on Amazon EMR. Spark, Trino 484 and DuckDB read the Merge-on-Read table at Iceberg format version 3. Spark, Amazon Athena and the Trino that EMR bundles read the Copy-on-Write table at Iceberg format version 2. Hudi publishes both tables through the AWS Glue Data Catalog.

Hudi writes Iceberg V3 tables on AWS: Hudi on Amazon EMR commits every write to an Iceberg table in AWS Glue and Amazon S3, with deletion vectors and row lineage, read by Amazon Athena, Spark on EMR, Trino and DuckDB

How Hudi writes Iceberg tables​

Hudi writes an Iceberg table the way Hudi writes a native Hudi table. Hudi's indexes locate records for upserts and deletes. Hudi plans and runs compaction, clustering, cleaning, archival and rollback. After each action, the plugin commits the result to the catalog as an Iceberg snapshot. Every query engine reading the table from the catalog sees the change.

Every Hudi action becomes an Iceberg snapshot: a write adds files and deletion vectors, compaction and clustering replace files, clean keeps the same files, rollback restores the earlier files, and archival expires snapshots
Every Hudi action becomes an Iceberg snapshot

Each transaction writes Hudi's metadata and Iceberg's metadata over the same data files. The Iceberg commit through the catalog decides whether the transaction completed:

How a Hudi commit becomes an Iceberg commit: the Hudi storage engine writes the data files to Amazon S3 (1), updates the Hudi timeline and metadata table under .hoodie (2), writes the Iceberg manifests and metadata.json under metadata (3), and swaps metadata_location in AWS Glue to the new metadata.json (4). A transaction completes only when step 4 succeeds; otherwise the transaction stays pending and the next write rolls the transaction back.
How a Hudi commit becomes an Iceberg commit

Hudi writes the data files (1) and records the transaction on the Hudi timeline (2). The plugin then writes the Iceberg metadata (3) and swaps the table's metadata location in Glue (4). The new Iceberg snapshot records the Hudi instant that the snapshot publishes. When Hudi loads the table, Hudi counts a transaction as complete only if an Iceberg snapshot records the transaction. If the Iceberg step fails, the transaction stays pending and the next write rolls the transaction back. So Hudi and Iceberg readers always see the same completed transactions.

Hudi readers use the Hudi timeline, metadata table and indexes, and keep Hudi's queries, incremental queries included. Iceberg readers use the catalog and the Iceberg metadata. Both read the same Parquet data files.

At Iceberg format version 3, Hudi also writes two features that the V3 spec adds. Both have counterparts in Hudi's own tables:

  • Deletion vectors. A Merge-on-Read write marks deleted and replaced rows in Puffin deletion vectors. The write does not rewrite the data files. Hudi's compaction later folds the deletion vectors into new base files, as compaction folds log files on a native Merge-on-Read table.
  • Row lineage. Every row gets a _row_id. An update keeps the row's _row_id, on Copy-on-Write and Merge-on-Read tables alike, so readers can follow a row across commits. Hudi tracks every record the same way, with a record key and a commit time per record.

Demo overview​

Hudi writer, table services and the Iceberg plugin run on Amazon EMR, write data files, deletion vectors and Iceberg metadata to Amazon S3, and commit every snapshot to the AWS Glue Data Catalog; Spark on EMR, Trino 484 and DuckDB read Iceberg format versions 2 and 3, while Amazon Athena and Trino 479 on EMR read Iceberg format version 2
The demo on AWS: one copy of the data on S3, one Iceberg table in AWS Glue

The demo writes two tables, the first with the DataFrame API and the second with Spark SQL. Every query engine below reads at least one of the two tables:

TableWritten withHudi table typeIceberg format versionRead by
trips_morDataFrame APIMerge-on-Read, with deletion vectors3 (the default)Spark, Trino 484, DuckDB
trips_cowSpark SQLCopy-on-Write2Spark, Amazon Athena, Trino on EMR

Either API can write either table type. Copy-on-Write works at Iceberg format version 2 or 3. Merge-on-Read needs Iceberg format version 3, for deletion vectors.

The environment is Amazon EMR 7.14.0 (Spark 3.5, Java 17) with Apache Iceberg 1.12.0. The tables live on Amazon S3, and Iceberg commits go through Iceberg's GlueCatalog. The demo does not use EMR's own Hudi and Iceberg applications. The Spark job brings the Hudi, Iceberg and XTable jars on --jars.

The sections below are the full demo: every command, in the order of the run, with the output of each. demo.py runs all the Spark steps at once. iceberg-evidence.sh prints the Glue and S3 state shown after the first write.

Build and start Spark​

Build Hudi from master and the Iceberg plugin from the XTable feature branch (to be released in Hudi 2.0 and the next XTable release), on the EMR primary node. The two Iceberg jars come from Maven Central:

# Hudi (JDK 11): installs 1.3.0-SNAPSHOT into the local Maven repository
git clone https://github.com/apache/hudi.git && cd hudi
mvn clean install -DskipTests -Dscala-2.12 -Dspark3.5 -pl packaging/hudi-spark-bundle,packaging/hudi-aws-bundle -am
cd ..

# XTable (JDK 17): builds against the Hudi snapshot installed above
git clone https://github.com/apache/incubator-xtable.git && cd incubator-xtable
git fetch origin pull/1055/head:ptf-iceberg && git checkout ptf-iceberg
./mvnw clean package -DskipTests \
-pl xtable-hudi-support/xtable-iceberg-pluggable-tf,xtable-hudi-support/xtable-hudi-support-extensions -am
cd ..

JARS_DIR=/home/hadoop/ptf-jars && mkdir -p $JARS_DIR
cp hudi/packaging/hudi-spark-bundle/target/hudi-spark3.5-bundle_2.12-1.3.0-SNAPSHOT.jar \
incubator-xtable/xtable-api/target/xtable-api-0.6.0-SNAPSHOT.jar \
incubator-xtable/xtable-core/target/xtable-core_2.12-0.6.0-SNAPSHOT.jar \
incubator-xtable/xtable-hudi-support/xtable-hudi-support-utils/target/xtable-hudi-support-utils-0.6.0-SNAPSHOT.jar \
incubator-xtable/xtable-hudi-support/xtable-iceberg-pluggable-tf/target/xtable-iceberg-pluggable-tf_2.12-0.6.0-SNAPSHOT.jar \
incubator-xtable/xtable-hudi-support/xtable-hudi-support-extensions/target/xtable-hudi-support-extensions_2.12-0.6.0-SNAPSHOT.jar \
$JARS_DIR/
MAVEN=https://repo1.maven.org/maven2/org/apache/iceberg
curl -sSfLo $JARS_DIR/iceberg-spark-runtime-3.5_2.12-1.12.0.jar \
$MAVEN/iceberg-spark-runtime-3.5_2.12/1.12.0/iceberg-spark-runtime-3.5_2.12-1.12.0.jar
curl -sSfLo $JARS_DIR/iceberg-aws-bundle-1.12.0.jar $MAVEN/iceberg-aws-bundle/1.12.0/iceberg-aws-bundle-1.12.0.jar

Create the Glue database for the tables. The cluster's instance profile needs Glue and S3 access:

aws glue create-database --database-input '{"Name": "<glue_db>"}'

Start Spark with Hudi, the Iceberg runtime, the Iceberg AWS bundle and the XTable Iceberg plugin on --jars, so the four share a single class loader. EMR puts EMR's AWS SDK on the Spark class path, ahead of --jars. Since Iceberg 1.12, the Iceberg AWS clients need the SDK inside the Iceberg AWS bundle. So the bundle also goes on the class path, ahead of EMR's entries.

The spark.hadoop.xtable.iceberg.* settings name the catalog and the Glue database that Hudi commits every snapshot to. Like Iceberg's own catalog settings, the plugin's catalog settings belong to the job, not to the table. The last settings let Spark's session catalog run Hudi's SQL commands, and add a glue Spark catalog that reads the Iceberg tables back:

PTF_JARS=$JARS_DIR/hudi-spark3.5-bundle_2.12-1.3.0-SNAPSHOT.jar,\
$JARS_DIR/iceberg-spark-runtime-3.5_2.12-1.12.0.jar,\
$JARS_DIR/iceberg-aws-bundle-1.12.0.jar,\
$JARS_DIR/xtable-api-0.6.0-SNAPSHOT.jar,\
$JARS_DIR/xtable-hudi-support-utils-0.6.0-SNAPSHOT.jar,\
$JARS_DIR/xtable-core_2.12-0.6.0-SNAPSHOT.jar,\
$JARS_DIR/xtable-iceberg-pluggable-tf_2.12-0.6.0-SNAPSHOT.jar,\
$JARS_DIR/xtable-hudi-support-extensions_2.12-0.6.0-SNAPSHOT.jar

EMR_DRIVER_CP=$(awk '$1 == "spark.driver.extraClassPath" {print $2}' /etc/spark/conf/spark-defaults.conf)
EMR_EXECUTOR_CP=$(awk '$1 == "spark.executor.extraClassPath" {print $2}' /etc/spark/conf/spark-defaults.conf)

pyspark --master yarn \
--jars "$PTF_JARS" \
--conf "spark.driver.extraClassPath=$JARS_DIR/iceberg-aws-bundle-1.12.0.jar:$EMR_DRIVER_CP" \
--conf "spark.executor.extraClassPath=./iceberg-aws-bundle-1.12.0.jar:$EMR_EXECUTOR_CP" \
--conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
--conf spark.kryo.registrator=org.apache.spark.HoodieSparkKryoRegistrar \
--conf spark.hadoop.xtable.iceberg.catalog.impl=org.apache.iceberg.aws.glue.GlueCatalog \
--conf spark.hadoop.xtable.iceberg.catalog.name=glue \
--conf spark.hadoop.xtable.iceberg.catalog.option.warehouse=s3://<bucket>/<prefix>/glue-warehouse \
--conf spark.hadoop.xtable.iceberg.namespace=<glue_db> \
--conf spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension,org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
--conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog \
--conf spark.sql.catalog.glue=org.apache.iceberg.spark.SparkCatalog \
--conf spark.sql.catalog.glue.catalog-impl=org.apache.iceberg.aws.glue.GlueCatalog \
--conf spark.sql.catalog.glue.warehouse=s3://<bucket>/<prefix>/glue-warehouse \
--conf spark.sql.catalog.glue.cache-enabled=false

The same Glue Data Catalog is also reachable through the AWS Glue Iceberg REST endpoint. There, Glue itself writes the new metadata file and applies each commit. To commit through the REST endpoint, replace the catalog.impl and catalog.option.warehouse lines of the pyspark command with the lines below. The write options stay the same:

  --conf spark.hadoop.xtable.iceberg.catalog.impl=org.apache.iceberg.rest.RESTCatalog \
--conf spark.hadoop.xtable.iceberg.catalog.option.uri=https://glue.<region>.amazonaws.com/iceberg \
--conf spark.hadoop.xtable.iceberg.catalog.option.warehouse=<account_id> \
--conf spark.hadoop.xtable.iceberg.catalog.option.rest.sigv4-enabled=true \
--conf spark.hadoop.xtable.iceberg.catalog.option.rest.signing-name=glue \
--conf spark.hadoop.xtable.iceberg.catalog.option.rest.signing-region=<region> \

Both routes commit to the same Glue table, so every reader below sees the same snapshots. The plugin loads any Iceberg catalog by class name, so other Iceberg REST catalogs work too.

Write with the DataFrame API​

The table format and the Iceberg format version are Hudi table settings, given on the first write. The Iceberg Configs on the table format page list every option. The options of trips_mor are:

options = {
"hoodie.table.name": "trips_mor",
"hoodie.datasource.write.recordkey.field": "key",
"hoodie.datasource.write.partitionpath.field": "region",
"hoodie.datasource.write.table.type": "MERGE_ON_READ",
# write the table as an Iceberg table, at format version 3 (the default)
"hoodie.table.format": "ICEBERG",
# write an update as a deletion vector on the old file plus the new row
"hoodie.write.updates.as.deletes.and.inserts": "true",
# write the Iceberg field IDs into every Parquet file, for readers such as DuckDB
"hoodie.avro.write.support.class": "org.apache.xtable.hudi.extensions.HoodieAvroWriteSupportWithFieldIds",
"hoodie.client.init.callback.classes": "org.apache.xtable.hudi.extensions.AddFieldIdsClientInitCallback",
"hoodie.datasource.write.row.writer.enable": "false",
}

def write(rows, operation):
(spark.createDataFrame(rows, "key string, region string, rider string, fare double")
.write.format("hudi").options(**options)
.option("hoodie.datasource.write.operation", operation)
.mode("append").save("s3://<bucket>/<prefix>/tables/trips_mor"))

The writer's default index supplies the row positions that the deletion vectors record.

The last three options are about Iceberg field IDs. Iceberg identifies columns by field ID. Some readers, such as DuckDB, need the field IDs inside each Parquet file. Other readers fall back to the table's name mapping. With the three options, XTable's Hudi writer extension writes the field IDs into every data file. Table services write data files too, so the table service calls below take the same three options.

Create the table​

The first write creates the table, as a Hudi table and as an Iceberg table registered in Glue:

write([("t1", "us", "alice", 12.5), ("t2", "us", "bob", 20.0), ("t3", "us", "carol", 8.0),
("t4", "eu", "dave", 15.0), ("t5", "eu", "erin", 30.0), ("t6", "eu", "frank", 9.5)], "insert")
spark.sql("SELECT key, region, rider, fare, _row_id FROM glue.<glue_db>.trips_mor ORDER BY key").show()
+---+------+-----+----+-------+
|key|region|rider|fare|_row_id|
+---+------+-----+----+-------+
| t1| us|alice|12.5| 3|
| t2| us| bob|20.0| 4|
| t3| us|carol| 8.0| 5|
| t4| eu| dave|15.0| 0|
| t5| eu| erin|30.0| 1|
| t6| eu|frank| 9.5| 2|
+---+------+-----+----+-------+

Glue lists the table as an Iceberg table. The Iceberg metadata lives under the table's base path, next to Hudi's .hoodie directory. The Iceberg metadata file records Iceberg format version 3 and the next row ID for row lineage. The metadata file command needs jq, which EMR does not install by default (sudo dnf install -y jq on EMR 7):

$ aws glue get-table --database-name <glue_db> --name trips_mor \
--query 'Table.{TableType:Parameters.table_type,MetadataLocation:Parameters.metadata_location}'
{
"TableType": "ICEBERG",
"MetadataLocation": "s3://<bucket>/<prefix>/tables/trips_mor/metadata/00002-d84f49a8-27e5-44a3-a327-69737bff8741.metadata.json"
}

$ aws s3 ls s3://<bucket>/<prefix>/tables/trips_mor/
PRE .hoodie/
PRE eu/
PRE metadata/
PRE us/

$ aws s3 cp <metadata_location> - | jq '{"format-version", "current-snapshot-id", "next-row-id"}'
{
"format-version": 3,
"current-snapshot-id": 1164779650644855055,
"next-row-id": 6
}

$ aws s3 cp s3://<bucket>/<prefix>/tables/trips_mor/.hoodie/hoodie.properties - | grep table.format
hoodie.table.format=ICEBERG

hoodie.properties records the table format. The Iceberg format version is recorded only when the first write sets it, and trips_mor uses the default. The catalog settings stay with the job.

Update and insert​

write([("t2", "us", "bob", 22.0), ("t5", "eu", "erin", 31.0), ("t7", "eu", "grace", 18.0)], "upsert")
spark.sql("SELECT key, region, rider, fare, _row_id FROM glue.<glue_db>.trips_mor ORDER BY key").show()
+---+------+-----+----+-------+
|key|region|rider|fare|_row_id|
+---+------+-----+----+-------+
| t1| us|alice|12.5| 3|
| t2| us| bob|22.0| 4|
| t3| us|carol| 8.0| 5|
| t4| eu| dave|15.0| 0|
| t5| eu| erin|31.0| 1|
| t6| eu|frank| 9.5| 2|
| t7| eu|grace|18.0| 7|
+---+------+-----+----+-------+

t2 and t5 keep the earlier _row_id values, and t7 gets a new _row_id. The files holding the old versions of t2 and t5 are not rewritten. Deletion vectors mark the old rows deleted instead:

spark.sql("SELECT content, file_format, partition.region, record_count FROM glue.<glue_db>.trips_mor.files").show()
+-------+-----------+------+------------+
|content|file_format|region|record_count|
+-------+-----------+------+------------+
| 0| PARQUET| us| 1|
| 0| PARQUET| eu| 2|
| 0| PARQUET| eu| 3|
| 0| PARQUET| us| 3|
| 1| PUFFIN| us| 1|
| 1| PUFFIN| eu| 1|
+-------+-----------+------+------------+

Delete​

write([("t3", "us", "carol", 8.0), ("t6", "eu", "frank", 9.5)], "delete")
spark.sql("SELECT key, region, rider, fare FROM glue.<glue_db>.trips_mor ORDER BY key").show()
+---+------+-----+----+
|key|region|rider|fare|
+---+------+-----+----+
| t1| us|alice|12.5|
| t2| us| bob|22.0|
| t4| eu| dave|15.0|
| t5| eu| erin|31.0|
| t7| eu|grace|18.0|
+---+------+-----+----+

Write with Spark SQL​

Hudi's SQL DDL and DML write Iceberg tables the same way. The second table, trips_cow, is a Copy-on-Write table at Iceberg format version 2. The Hudi SQL table lives in Spark's session catalog, in a separate database (hudi_sql here). Hudi publishes the Iceberg table as <glue_db>.trips_cow in Glue. Keep the Hudi SQL table and the Iceberg table in different databases, because both use the name trips_cow. On an EMR cluster that uses the Glue Data Catalog as the Spark metastore, hudi_sql is a Glue database too:

spark.sql("CREATE DATABASE IF NOT EXISTS hudi_sql")
spark.sql("""
CREATE TABLE hudi_sql.trips_cow (key STRING, rider STRING, fare DOUBLE, region STRING)
USING hudi
PARTITIONED BY (region)
LOCATION 's3://<bucket>/<prefix>/tables/trips_cow'
TBLPROPERTIES (
primaryKey = 'key',
type = 'cow',
'hoodie.table.format' = 'ICEBERG',
'hoodie.table.format.iceberg.format.version' = '2'
)""")

spark.sql("""INSERT INTO hudi_sql.trips_cow VALUES
('t1', 'alice', 12.5, 'us'), ('t2', 'bob', 20.0, 'us'), ('t3', 'carol', 8.0, 'us'),
('t4', 'dave', 15.0, 'eu'), ('t5', 'erin', 30.0, 'eu'), ('t6', 'frank', 9.5, 'eu')""")
spark.sql("UPDATE hudi_sql.trips_cow SET fare = 22.0 WHERE key = 't2'")
spark.sql("""
MERGE INTO hudi_sql.trips_cow t
USING (SELECT 't5' AS key, 'erin' AS rider, 31.0 AS fare, 'eu' AS region
UNION ALL SELECT 't7', 'grace', 18.0, 'eu') s
ON t.key = s.key
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *""")
spark.sql("DELETE FROM hudi_sql.trips_cow WHERE key IN ('t3', 't6')")

spark.sql("SELECT key, region, rider, fare FROM glue.<glue_db>.trips_cow ORDER BY key").show()
spark.sql("SELECT snapshot_id, operation FROM glue.<glue_db>.trips_cow.snapshots ORDER BY committed_at").show()
+---+------+-----+----+
|key|region|rider|fare|
+---+------+-----+----+
| t1| us|alice|12.5|
| t2| us| bob|22.0|
| t4| eu| dave|15.0|
| t5| eu| erin|31.0|
| t7| eu|grace|18.0|
+---+------+-----+----+

+-------------------+---------+
| snapshot_id|operation|
+-------------------+---------+
| 803897671289576669| append|
|7134587319440766087|overwrite|
|8271945878855653444|overwrite|
|8288069596034629051|overwrite|
+-------------------+---------+

The Iceberg table holds the same rows as trips_mor, and each SQL statement is one Iceberg snapshot. The INSERT is an append. UPDATE, MERGE INTO and DELETE rewrite files of the Copy-on-Write table, so each of the three statements is an overwrite.

Run table services from Hudi​

Hudi plans and runs table services in the writing job, here through Hudi's SQL procedures. Each table service that changes files commits an Iceberg snapshot to Glue, like any write. Compaction folds the deletion vectors of the Merge-on-Read table into new base files. Hudi schedules a compaction after enough delta commits since the last compaction, five by default (hoodie.compact.inline.max.delta.commits). trips_mor has three delta commits, so the call lowers the threshold to one. The call also passes the three field ID options, so the compacted files keep the field IDs:

fid = ",".join(f"{k}={options[k]}" for k in (
"hoodie.avro.write.support.class", "hoodie.client.init.callback.classes", "hoodie.datasource.write.row.writer.enable"))
spark.sql(f"""CALL run_compaction(op => 'scheduleAndExecute', path => 's3://<bucket>/<prefix>/tables/trips_mor',
options => 'hoodie.compact.inline.max.delta.commits=1,{fid}')""")
spark.sql("SELECT content, file_format, partition.region, record_count FROM glue.<glue_db>.trips_mor.files").show()
+-------+-----------+------+------------+
|content|file_format|region|record_count|
+-------+-----------+------+------------+
| 0| PARQUET| eu| 1|
| 0| PARQUET| us| 1|
| 0| PARQUET| us| 1|
| 0| PARQUET| eu| 2|
+-------+-----------+------+------------+

After compaction, the table has only Parquet data files. No deletion vectors remain.

Clustering rewrites the files of each partition, sorted by key, with the same field ID options:

spark.sql(f"CALL run_clustering(path => 's3://<bucket>/<prefix>/tables/trips_mor', options => '{fid}')")

Cleaning and archival run automatically after commits. Cleaning deletes the file versions that no retained commit needs. Archival expires the Iceberg snapshots of the instants that leave Hudi's active timeline. Time travel to a snapshot works as long as the snapshot and the data files the snapshot references are still available. Rolling back a Hudi commit commits a new Iceberg snapshot that restores the earlier files.

The table's Iceberg history now has one snapshot per Hudi action. Each snapshot's summary lists the data files and deletion vectors the snapshot added or removed:

spark.sql("""SELECT snapshot_id, operation, summary['added-data-files'] AS added_files,
summary['deleted-data-files'] AS removed_files, summary['added-delete-files'] AS added_dvs,
summary['total-records'] AS total_records
FROM glue.<glue_db>.trips_mor.snapshots ORDER BY committed_at""").show(truncate=False)
+-------------------+---------+-----------+-------------+---------+-------------+
|snapshot_id |operation|added_files|removed_files|added_dvs|total_records|
+-------------------+---------+-----------+-------------+---------+-------------+
|1164779650644855055|append |2 |NULL |NULL |6 |
|795897627086519028 |overwrite|2 |NULL |2 |9 |
|106757900884805991 |delete |NULL |NULL |2 |9 |
|1018260257044221351|replace |2 |2 |NULL |5 |
|7373173295108430238|replace |2 |4 |NULL |5 |
+-------------------+---------+-----------+-------------+---------+-------------+

The upsert (overwrite) adds two data files and two deletion vectors, and the delete adds only deletion vectors. total_records counts the rows in the data files, deleted rows included, so the count stays at 9 until compaction. The first replace is compaction: compaction rewrites the two files with deletion vectors and drops the deleted rows, and the count falls to 5. The second replace is clustering, which rewrites four files into two.

Read the tables​

Iceberg readers find the tables in the Glue Data Catalog and need no Hudi setup. Hudi readers read the same tables through Hudi.

Spark on EMR​

The glue catalog from the pyspark command reads both tables, including time travel to the first snapshot:

first = spark.sql("SELECT snapshot_id FROM glue.<glue_db>.trips_mor.snapshots ORDER BY committed_at LIMIT 1").first()[0]
spark.sql(f"SELECT key, region, rider, fare FROM glue.<glue_db>.trips_mor VERSION AS OF {first} ORDER BY key").show()
+---+------+-----+----+
|key|region|rider|fare|
+---+------+-----+----+
| t1| us|alice|12.5|
| t2| us| bob|20.0|
| t3| us|carol| 8.0|
| t4| eu| dave|15.0|
| t5| eu| erin|30.0|
| t6| eu|frank| 9.5|
+---+------+-----+----+

Live rows inserted or updated since the first snapshot​

Incremental processing is where Hudi started. A Hudi incremental query returns only the rows of the commits that completed after a given time. Here the start time is the commit time of the first Iceberg snapshot, the insert:

path = "s3://<bucket>/<prefix>/tables/trips_mor"
begin = spark.sql(f"""SELECT date_format(committed_at, 'yyyyMMddHHmmssSSS')
FROM glue.<glue_db>.trips_mor.snapshots WHERE snapshot_id = {first}""").first()[0]
(spark.read.format("hudi").option("hoodie.datasource.query.type", "incremental")
.option("hoodie.datasource.read.begin.instanttime", begin).load(path)
.select("_hoodie_commit_time", "key", "rider", "fare").orderBy("key").show(truncate=False))
+-------------------+---+-----+----+
|_hoodie_commit_time|key|rider|fare|
+-------------------+---+-----+----+
|20261201152230556 |t2 |bob |22.0|
|20261201152230556 |t5 |erin |31.0|
|20261201152230556 |t7 |grace|18.0|
+-------------------+---+-----+----+

Iceberg V3 row lineage lets Iceberg readers answer the same question. Each row carries _last_updated_sequence_number, the sequence number of the snapshot that last wrote the row. The insert is the table's first snapshot, with sequence number 1:

spark.sql("""SELECT key, rider, fare, _row_id, _last_updated_sequence_number
FROM glue.<glue_db>.trips_mor WHERE _last_updated_sequence_number > 1 ORDER BY key""").show()
+---+-----+----+-------+-----------------------------+
|key|rider|fare|_row_id|_last_updated_sequence_number|
+---+-----+----+-------+-----------------------------+
| t2| bob|22.0| 4| 2|
| t5| erin|31.0| 1| 2|
| t7|grace|18.0| 7| 2|
+---+-----+----+-------+-----------------------------+

One table, two readers, the same answer: t2 and t5 were updated after the insert, and t7 was inserted. t3 and t6 were deleted, so neither query returns them. t1 and t4 keep sequence number 1, even though compaction and clustering rewrote the files holding both rows.

Amazon Athena (Iceberg format version 2)​

Athena reads trips_cow from Glue with no setup:

SELECT key, region, rider, fare FROM "<glue_db>"."trips_cow" ORDER BY key;
key  region  rider  fare
t1 us alice 12.5
t2 us bob 22.0
t4 eu dave 15.0
t5 eu erin 31.0
t7 eu grace 18.0

Athena does not read Iceberg format version 3 yet:

SELECT count(*) FROM "<glue_db>"."trips_mor";
GENERIC_INTERNAL_ERROR: Iceberg format version 3 is not supported

Trino on EMR (Iceberg format version 2)​

The Trino that EMR installs reads Iceberg format versions 1 and 2. Give EMR's Trino an Iceberg catalog on Glue. On a running cluster, add /etc/trino/conf/catalog/iceberg.properties on every node that runs Trino, then restart Trino. On a new cluster, the trino-connector-iceberg configuration classification does the same:

connector.name=iceberg
iceberg.catalog.type=glue
# EMR 7.7.0 and later
fs.native-s3.enabled=true
$ trino-cli --catalog iceberg --schema <glue_db> --execute "SELECT key, region, rider, fare FROM trips_cow ORDER BY key"
"t1","us","alice","12.5"
"t2","us","bob","22.0"
"t4","eu","dave","15.0"
"t5","eu","erin","31.0"
"t7","eu","grace","18.0"

Open source Trino (Iceberg format version 3)​

Trino added Iceberg format version 3, with deletion vectors and row lineage, in release 480. The demo runs a single-node Trino 484 on the EMR primary node. The single-node server listens on port 8095, clear of EMR's own Trino. Trino 484 needs Java 25: any Java 25 JDK works (the demo used Amazon Corretto 25), with <java-25-home> below pointing at the JDK. Download the server from Maven Central and start the server:

curl -fLO https://repo1.maven.org/maven2/io/trino/trino-server/484/trino-server-484.tar.gz
tar xzf trino-server-484.tar.gz && cd trino-server-484 && mkdir -p etc/catalog
printf '%s\n' node.environment=demo node.id=trino-v3 node.data-dir=/mnt/trino-v3 > etc/node.properties
printf '%s\n' -server -Xmx4G > etc/jvm.config
printf '%s\n' coordinator=true node-scheduler.include-coordinator=true \
http-server.http.port=8095 discovery.uri=http://localhost:8095 > etc/config.properties
printf '%s\n' connector.name=iceberg iceberg.catalog.type=glue hive.metastore.glue.region=<region> \
fs.native-s3.enabled=true s3.region=<region> > etc/catalog/iceberg.properties
JAVA_HOME=<java-25-home> bin/launcher start

Download the Trino CLI into the same directory:

curl -fLo trino https://repo1.maven.org/maven2/io/trino/trino-cli/484/trino-cli-484-executable.jar && chmod +x trino

The CLI needs Java 25 too, first on PATH. Query the Merge-on-Read table, with the row lineage ID of each row:

$ PATH=<java-25-home>/bin:$PATH ./trino --server localhost:8095 --catalog iceberg --schema <glue_db> \
--execute 'SELECT key, region, rider, fare, "$row_id" FROM trips_mor ORDER BY key'
"t1","us","alice","12.5","3"
"t2","us","bob","22.0","4"
"t4","eu","dave","15.0","0"
"t5","eu","erin","31.0","1"
"t7","eu","grace","18.0","7"

DuckDB (Iceberg format version 3)​

DuckDB 2.0.1 reads Iceberg format version 2 and 3 tables, with deletion vectors and row lineage. DuckDB reads a table either from the table's metadata file or through the Glue Data Catalog, using the Glue Iceberg REST endpoint. DuckDB needs the field IDs in the data files, which trips_mor has:

$ duckdb -c "
INSTALL iceberg; INSTALL aws; INSTALL httpfs; LOAD iceberg; LOAD aws; LOAD httpfs;
CREATE SECRET (TYPE s3, PROVIDER credential_chain, REGION '<region>');
ATTACH '<account_id>' AS glue (TYPE iceberg, ENDPOINT_TYPE glue);
SELECT key, region, rider, fare, _row_id FROM glue.<glue_db>.trips_mor ORDER BY key;"
┌─────────┐
│ Success │
│ boolean │
├─────────┤
│ true │
└─────────┘
┌─────────┬─────────┬─────────┬────────┬─────────┐
│ key │ region │ rider │ fare │ _row_id │
│ varchar │ varchar │ varchar │ double │ int64 │
├─────────┼─────────┼─────────┼────────┼─────────┤
│ t1 │ us │ alice │ 12.5 │ 3 │
│ t2 │ us │ bob │ 22.0 │ 4 │
│ t4 │ eu │ dave │ 15.0 │ 0 │
│ t5 │ eu │ erin │ 31.0 │ 1 │
│ t7 │ eu │ grace │ 18.0 │ 7 │
└─────────┴─────────┴─────────┴────────┴─────────┘

Both tables end with the same five trips. On trips_mor, Spark, Trino 484 and DuckDB also agree on the row IDs.

Learn more​

The Pluggable Table Format documentation has the details. The documentation's Apache Iceberg section lists the supported features, the configs and the Iceberg spec support. The section also lists the work still in development. For questions and feedback, post on the Hudi Slack or open an issue on GitHub.