Apache XTable with Iceberg: data paths and where targets write
Why tableDataPath decides whether partition values come out right, where the Hudi and Delta targets land, and how to find an Iceberg table by path or through a catalog.
- Convert an Iceberg table to Hudi and Delta
- Why the data path matters, and where each target writes
- Index an Iceberg table for point lookups
- Iceberg’s own maintenance
- Failures you can hit with an Iceberg source
- Key takeaways
- References
- Trademarks
TL;DR
With Iceberg as the source, XTable reads the snapshots and manifests and writes Hudi and Delta metadata over the same data files. Nothing is copied.
Everything else follows from that sentence:
- Iceberg does not promise one data folder, so XTable has to be told where the files are. Leave out
tableDataPathfor a table with adata/folder and the Hudi copy records partition values asdata/city_id=nyc.- The targets do not write to one place. The Hudi metadata goes under the data path, while the Delta log stays at the base path beside Iceberg’s
metadata/.- The Hudi target can also carry a secondary index on one column. Spark sessions with the XTable extensions use it to read one file instead of many for a point lookup.
- The index never changes a result. When it is behind the table the query reads everything and warns, and a filter fails only when the indexed column’s name now belongs to another field.
- The index is built by a sync, either on a Spark cluster or on one machine with the Hudi Spark bundle added to the classpath.
An Iceberg table is the source whose files you are least likely to find where a
tool expects them. A Hadoop catalog keeps data in a data/ folder next to
metadata/, a REST catalog may keep it in another bucket, and the table
location says where the metadata is, not the files. Most of what goes wrong with
an Iceberg source is about that, and the rest is about the one thing Iceberg
sources can do that the others cannot: carry a secondary index. The answers
below were checked on 0.5.0-incubating. The build and every flag are in the
cheat sheet, and the Hudi
source is in
Apache Hudi as an XTable source.
Convert an Iceberg table to Hudi and Delta
Create a small partitioned Iceberg table with a Hadoop catalog. This ran on
Spark 3.5.9 with the Iceberg 1.9.2 runtime, the version XTable bundles:
pyspark \
--packages org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2 \
--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=file:///tmp/warehouse"
trips = spark.createDataFrame(
[("trip-%d" % (1001 + i), "rider-%d" % (10 + i % 5), round(10 + i * 7.25, 2),
1758000000 + i * 60, ["sf", "nyc"][i % 2]) for i in range(6)],
["trip_id", "rider_id", "fare_amount", "updated_at", "city_id"])
trips.writeTo("local.db.trips_ice").partitionedBy(trips.city_id).using("iceberg").create()
The table directory holds Iceberg’s metadata and the data folder side by side:
/tmp/warehouse/db/trips_ice/ data metadata
data/ city_id=nyc city_id=sf
Point XTable at the table directory, not at the warehouse or the data folder.
Pointing it anywhere else fails with
NoSuchTableException: Table does not exist at location: file:///.../nope.
Save this as ice_sync.yaml:
sourceFormat: ICEBERG
targetFormats:
- HUDI
- DELTA
datasets:
- tableBasePath: file:///tmp/warehouse/db/trips_ice
tableDataPath: file:///tmp/warehouse/db/trips_ice/data
tableName: trips_ice
namespace: db
java -jar "$XTABLE_JAR" --datasetConfig ice_sync.yaml
INFO ConversionController:215 - Sync is successful for the following formats HUDI,DELTA
Why the data path matters, and where each target writes
tableBasePath locates the table and its metadata. tableDataPath locates the
data files. Without it, XTable treats the base path as the data root and the
partition folders come out wrong. Syncing the same table with only
tableBasePath, then reading the Hudi copy, returned the partition column like
this:
city_id values ['data/city_id=nyc', 'data/city_id=sf']
With tableDataPath set the values were nyc and sf.

The two runs also put the targets in different places:
without tableDataPath: .hoodie _delta_log metadata data/
with tableDataPath: _delta_log metadata data/ (holds city_id=nyc, city_id=sf, .hoodie)

With the data path set, the Hudi .hoodie/ directory lands under data/, while
_delta_log/ and Iceberg’s metadata/ stay at the base path. Read the Hudi copy
from the data path and the Delta copy from the base path:
spark.read.format("hudi").load("file:///tmp/warehouse/db/trips_ice/data").show()
spark.read.format("delta").load("file:///tmp/warehouse/db/trips_ice").show()
Both returned the six rows. Do not assume the data sits at <basePath>/data on
other catalogs. A table written by a REST or Glue catalog can keep its files
elsewhere, and tableDataPath is how XTable finds them.
Finding the table through a catalog. --icebergCatalogConfig takes a YAML
file with three keys, and with it an Iceberg source is found through the catalog
instead of by path. A Hadoop catalog is enough for a test:
catalogImpl: org.apache.iceberg.hadoop.HadoopCatalog
catalogName: local
catalogOptions:
warehouse: file:///tmp/warehouse
Index an Iceberg table for point lookups
Added in 0.5.0, this is the one feature that changes how a query runs. XTable can
keep a secondary index on one column of an Iceberg table. The index maps each
value to the data files that hold it and is stored as a Hudi metadata table
under .hoodie/ in the table’s data folder. Two parts make it work: a sync
builds and maintains the index, and Spark sessions with the XTable extensions
use it.
Build it with a sync whose target is Hudi, with the index settings in
targetProperties:
sourceFormat: ICEBERG
targetFormats:
- HUDI
datasets:
- tableBasePath: file:///warehouse/db/cust
tableDataPath: file:///warehouse/db/cust/data
tableName: cust
namespace: db
targetProperties:
HUDI:
xtable.hudi.target.table_version: '9'
xtable.hudi.target.execution.engine: spark
xtable.hudi.target.secondary.index.column: email
It must run where Hudi’s Spark classes exist. java -jar on the bundled RunSync
jar failed with
NoClassDefFoundError: org/apache/hudi/client/common/HoodieSparkEngineContext.
Two setups work, and both were run:
# A Spark cluster: the index build is spread across the executors
$SPARK_HOME/bin/spark-submit \
--packages org.apache.hudi:hudi-spark3.5-bundle_2.12:1.2.1,org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2 \
--conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
--class org.apache.xtable.spark.XTableSparkSync \
xtable-spark-runtime_2.12-0.5.0-incubating.jar \
--datasetconfig index_config.yaml
# One machine: RunSync with the Hudi Spark 3.4 bundle after the bundled jar
java -cp "$XTABLE_JAR:hudi-spark3.4-bundle_2.12-1.2.1.jar" \
org.apache.xtable.utilities.RunSync --datasetConfig index_config.yaml
The bundled jar carries Spark 3.4, which is why the second command takes the
Spark 3.4 Hudi bundle. Both produced the same .hoodie/metadata/ partitions.
The build reads every data file, so use the cluster for a large table.
On a table of 2,000 rows in 40 files the build created .hoodie/metadata/
partitions named column_stats, files, record_index and secondary_index_email. The
index covers one top-level string, int or bigint column and that column
cannot change later.
Use it with the XTable extensions listed after the Iceberg ones, and Hudi’s Kryo serializer:
spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions,org.apache.xtable.spark.extensions.XTableSparkSessionExtensions
spark.serializer=org.apache.spark.serializer.KryoSerializer
Put xtable-spark-runtime, the Hudi Spark bundle and the Iceberg runtime on
spark.driver.extraClassPath and spark.executor.extraClassPath rather than
--jars, so XTable and Hudi load from the same class loader. Queries do not
change:
SELECT id, email FROM local.db.cust WHERE email = 'user1234@example.com';
The driver log says whether the index was used:
IndexPruningRule: Using the index of local.db.cust on email for 1 keys: reading 1 of 40 candidate files
The same query with spark.xtable.index.pruning.enabled=false returned the same
row, so a missing or stale index costs time and never correctness.
| Setting | Default | Meaning |
|---|---|---|
spark.xtable.index.pruning.enabled |
true |
Use indexes for queries |
spark.xtable.index.pruning.minCandidateFiles |
32 |
Fewest files a scan may read before an index is used |
spark.xtable.index.pruning.minCandidateBytes |
1073741824 |
Fewest bytes a scan may read before an index is used |
spark.xtable.index.pruning.maxKeys |
10000 |
Most filter values that are looked up |
The first two thresholds mean a small table is never indexed in practice, because
a lookup is itself a Spark job. The check above lowered both to 1. The index is
skipped for time travel, branches and tags, joins, MERGE, UPDATE and DELETE,
and only Spark sessions with the extensions use it.
When the index falls behind. The index records the Iceberg snapshot it was synced to. After a commit to the table that the sync has not seen, the query still returns the right rows, reads the table the normal way, and logs a warning that names both snapshots:
WARN IndexPruningRule: Not using the index of local.db.cust on email: it is synced to snapshot 4323525969127622808, but the table is at 7073719183851107756. Run the XTable sync of the table to update the index
After an Iceberg insert, the lookup returned the same row as before. Rebuilding
with a sync restored the Using the index ... line.
When a query fails. The index keys its column by name. Renaming email to
mail did not break anything, because a filter on mail is simply not indexed.
The failure comes when the old name is given to a different field. After adding
a new email column and filtering on it, the query failed:
org.apache.xtable.spark.extensions.optimizer.IndexedColumnRenamedException: The index of local.db.cust on email was synced when email named another field. Rebuild the index after the next commit to the table, or set s...
With spark.xtable.index.pruning.enabled=false the same filter ran and returned
no rows, because the new column was empty. Rebuild the index after the next
commit, or turn pruning off for the session while you repair it.
The warning is logged at WARN, but the Using the index line is INFO, so
set the org.apache.xtable logger to INFO to see which queries used it.
Iceberg’s own maintenance
The same shared-file rule as in the Hudi post applies in this direction. A
Hudi or Delta target lists the files it was synced with, so an Iceberg
expire_snapshots or remove_orphan_files that deletes one of them leaves the
target listing a file that is gone. Only the Hudi cleaner case was tested, so
treat this one as the same mechanism, not as a measured result. Keep the sync
interval shorter than your snapshot expiry, and see
the cleaner section of the Hudi post
for the failure and its recovery.
One bug is fixed on the development branch after 0.5.0 and is not in it: an
Iceberg source whose data files omit column statistics threw a
NullPointerException. If you hit it on 0.5.0, check the next release before
working around it.
Failures you can hit with an Iceberg source
| Symptom | Cause | Fix |
|---|---|---|
NoSuchTableException: Table does not exist at location |
tableBasePath is not the table directory |
Point at the directory that holds metadata/ |
Hudi partition values read data/city_id=nyc |
tableDataPath not set for a table whose files live under data/ |
Add tableDataPath, and re-sync into a clean target |
NoClassDefFoundError: org/apache/hudi/client/common/HoodieSparkEngineContext |
Building the index with java -jar and no Hudi Spark bundle |
Use XTableSparkSync, or put the Hudi Spark 3.4 bundle on the RunSync classpath |
WARN IndexPruningRule: Not using the index ... |
The index is synced to an older snapshot than the table | Run the sync again |
IndexedColumnRenamedException on a filter |
The indexed column’s name now belongs to another field | Rebuild the index after the next commit, or disable pruning for the session |
UnsupportedClassVersionError ... class file version 61.0 reading Iceberg |
Iceberg 1.11 or later on Java 11 | Run the reader on Java 17 |
Key takeaways
With an Iceberg source the first thing to get right is where the files are, and
everything else follows from that. Set tableDataPath, check the partition
values in the Hudi copy, and read each target from the directory it was written
to. The index is the part worth adding after that: it costs one more property on
the Hudi target, it falls back safely when it is behind, and it fails loudly only
when a column name changes meaning.
References
- Secondary index for Iceberg tables for the index, with the jar choice for each deployment
- Features and limitations for the Hudi target properties
- Apache XTable cheat sheet for the build, every flag and the troubleshooting table
- Apache Hudi as an XTable source for table versions, Merge-on-Read and the cleaner
Trademarks
Apache XTable (incubating), Apache Iceberg, Apache Hudi, Apache Spark, Apache Parquet and Apache are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries. Delta Lake is a trademark of the Linux Foundation. All other marks are the property of their respective owners.
Found this useful?
These posts and tools are free. If one saved you an afternoon, you can buy me a coffee.
Comments
Questions, corrections and reviews are welcome. Sign in with GitHub to post; comments are stored in this site's public GitHub Discussions.