All posts

Contributing to Apache XTable: sources, targets and catalogs

A developer's guide from the release source: the repository map, the three extension points and how each is discovered at run time, what a source, a target and a catalog client must implement, the build and test commands that were run, the shaded-jar licence rules, and the RFC process.

7 min read Lakehouse

TL;DR

XTable has three extension points, all declared as interfaces in xtable-api: a source, a target and a catalog client. Each is found in a different way.

  • A source is a ConversionSource plus a ConversionSourceProvider, and it is found by a class name in the converters YAML.
  • A target is a ConversionTarget, and it is found by ServiceLoader through a line in META-INF/services in xtable-core.
  • A catalog client is a CatalogSyncClient, and a CatalogConversionSource if the catalog can be a source. Both are registered through ServiceLoader in the module that owns them.
  • Build with Java 11 and the Maven wrapper. spotless:check and a targeted unit test both passed in a clean container.
  • Dependency changes in a shaded module carry extra steps for the licence metadata, and the project’s CI enforces them.
  • Large changes start as an RFC. RFC 2, which proposes converting Delta deletion vectors to Iceberg, shows the format.

The series so far has treated XTable as a tool. It is also a codebase, and everything below was read from the 0.5.0-incubating tag. The commands labelled as run were run.

Three extension points: a source is a ConversionSource and a provider found by a class name in the converters YAML, a target is a ConversionTarget found by ServiceLoader in xtable-core, and a catalog client is a CatalogSyncClient and CatalogConversionSource found by ServiceLoader in the HMS or AWS module

The repository map

From the project’s own AGENTS.md:

Module Holds
xtable-api Public interfaces and the SPI contracts
xtable-core Conversion logic, the sync flow, and the source and target implementations
xtable-hudi-support Hudi-specific modules, including xtable-iceberg-pluggable-tf
xtable-utilities The RunSync and RunCatalogSync CLI and its shaded jar
xtable-aws, xtable-hive-metastore The Glue and Hive Metastore catalog support, shaded
xtable-service The REST service
xtable-spark-runtime, xtable-spark-extensions The Spark entry points and the index extensions
spec, rfc Design documents and proposals
release/scripts Release and licence automation

The guide’s advice is to work in the narrowest module that owns the behaviour, and to verify every affected module when a change crosses a boundary.

Add a source

A source implements ConversionSource<COMMIT>, whose methods are the contract the controller calls:

getTable(commit)              getCurrentTable()           getCurrentSnapshot()
getTableChangeForCommit(c)    getCommitsBacklog(instants) isIncrementalSyncSafeFrom(instant)
getCommitIdentifier(commit)

A ConversionSourceProvider<COMMIT> builds one for a given SourceTable. It has one abstract method, getConversionSourceInstance(SourceTable), and an init that receives the Hadoop configuration. The helper interfaces in spi.extractor (SchemaExtractor, SnapshotExtractor, ChangesExtractor, TableExtractor, SourcePartitionSpecExtractor, DataFileIterator) are what each existing source uses to organise the work.

To make it available, add it to the converters config. RunSync reads tableFormatConverters and instantiates conversionSourceProviderClass by reflection, so the class needs a public no-argument constructor and the jar must be on the classpath:

tableFormatConverters:
  MYFORMAT:
    conversionSourceProviderClass: com.example.MyFormatConversionSourceProvider

The XTableSyncService in the Spark runtime has a hard-coded switch over the five known formats instead, so a new source there needs a change in that class.

What to implement. The smallest source in the repository is Paimon, with six classes under xtable-core/.../paimon: PaimonConversionSource, PaimonConversionSourceProvider, PaimonDataFileExtractor, PaimonPartitionExtractor, PaimonSchemaExtractor and PaimonStatsExtractor. Copy that shape. Your work is four mappings into the internal model: schema to InternalSchema, partition fields to InternalPartitionField, data files to InternalDataFile with statistics, and commits to TableChange. The most important method is isIncrementalSyncSafeFrom, because the controller falls back to a snapshot pass whenever it returns false. The four existing implementations show the pattern: check that history still reaches the instant.

Add a target

Adding a target in four steps: implement ConversionTarget, register it in META-INF/services, test it, then run spotless and the CI checks

A target implements ConversionTarget, whose methods mirror what a table format needs:

init(targetTable, conf)         beginSync(table)            syncMetadata(metadata)
syncSchema(schema)              syncPartitionSpec(spec)     syncFilesForSnapshot(files)
syncFilesForDiff(diff)          completeSync()              getTableMetadata()
getTableFormat()                getTargetCommitIdentifier(sourceId)
isIncrementalSyncSafe()         (default true)

TableFormatSync calls them in a fixed order: beginSync, syncMetadata, syncSchema, syncPartitionSpec, the file sync, completeSync. syncMetadata comes first and must persist the TableSyncMetadata somewhere that getTableMetadata can read back, because that entry is how the next run decides its mode. The Iceberg target stores it as the XTABLE_METADATA table property and snapshot summary entry. isIncrementalSyncSafe lets a target force a snapshot pass, as the Hudi target does when its column statistics index is missing.

Register the class with one line in xtable-core/src/main/resources/META-INF/services/org.apache.xtable.spi.sync.ConversionTarget. The file lists four today: Hudi, Delta, the Delta Kernel target and Iceberg. ConversionTargetFactory matches on getTableFormat(), and skips a target whose engine library is missing with a warning, which is why a missing dependency shows up as Target format is not yet supported.

Add a catalog client

A CatalogSyncClient<TABLE> handles one catalog:

getCatalogId()  getCatalogType()  getStorageLocation(table)  hasDatabase(id)
createDatabase(id)  getTable(id)  createTable(table, id)  createOrReplaceTable(table, id)
dropTable(table, id)  init(catalogConfig, tableFormat, conf)

CatalogSync calls hasDatabase, createDatabase, getTable, then createTable, createOrReplaceTable or refreshTable, as the CatalogSync post describes. A catalog that can also be a source adds a CatalogConversionSource. Both are registered under META-INF/services in the owning module, as the HMS and AWS modules do. Each catalog also has a config class with externalCatalog.* properties, a schema extractor for its type system, and a table builder per format.

Build and test

Use Java 11 and the Maven wrapper. The commands below are from AGENTS.md, and two were run on a clean checkout in a Java 11 container:

./mvnw -pl xtable-api spotless:check
./mvnw -pl xtable-core -Dtest=TestConversionTargetFactory -DskipITs test
Spotless.Java is keeping 75 files clean - 0 needs changes to be clean
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

The root pom.xml wires three flags: -DskipTests for everything, -DskipUTs for the unit tests and -DskipITs for the integration tests. Use ./mvnw spotless:apply to fix formatting. Run the narrowest module while you iterate, and a broader ./mvnw verify for shared build logic or cross-module APIs. Integration tests are in ITConversionController, which runs the format pairs through sync modes and partitioning, and the test tables in TestSparkHudiTable, TestIcebergTable, TestSparkDeltaTable and TestPaimonTable give you a way to create real tables. A loadtest package holds a load test. The full integration suite was not run.

Dependencies and shaded jars

xtable-aws, xtable-hive-metastore, xtable-hudi-support-extensions, xtable-spark-runtime and xtable-utilities are shaded, and they carry rules that a plain dependency bump breaks. From AGENTS.md:

  1. Update the pom.xml.
  2. For a shaded module, regenerate the runtime dependency tree and keep the shade <artifactSet><includes> list matching it, runtime dependencies only.
  3. Run python3 release/scripts/generate_shaded_license_metadata.py.
  4. Run release/scripts/validate_shaded_license_coverage.sh.
  5. Run the narrowest Maven verification for the changed modules.

The pull request must pass mvn-ci-build.yml and mvn-license-check.yml, which runs apache-rat:check and the licence validators. Keep ASF licence headers in new files.

Process

The README asks you to open a GitHub issue first and points to the community pages for guidelines. For a design change, the repository has an rfc folder with a template and two proposals. RFC 2 proposes converting Delta deletion vectors to Iceberg, which would close the gap in the compatibility post, where deleted rows stay visible in targets. It is a proposal and is not in 0.5.0.

Places the series found gaps

These came out of reading the code and running it, and each is a candidate to raise as an issue after checking the current tracker:

  • RunSync and RunCatalogSync exit 0 when a sync fails, while XTableSparkSync exits 1.
  • Two error messages tell you to run a full sync, and neither the CLI nor the Spark runtime has an option for one.
  • The Delta Kernel target cannot evolve a schema or write generated columns.
  • The Hudi target rejects BUCKET partitions.
  • The Iceberg source ignores delete files.
  • The Hive Metastore module does not bundle the Hive classes its client needs.

Checked against the source

Claim Where
Interface methods ConversionSource, ConversionTarget, CatalogSyncClient, ConversionSourceProvider
How sources and targets are found RunSync.getConversionSourceProvider, ConversionTargetFactory, META-INF/services files
The Spark runtime’s fixed source switch XTableSyncService.sourceProviderFor
Repository map, commands, shaded module rules, CI AGENTS.md
RFCs the rfc folder
Test classes xtable-core/src/test

Spotless and the one unit test were run in a maven:3.9-eclipse-temurin-11 container.

Key takeaways

The extension model is small and uniform. Implement the interface, register it the way the interface is found, copy the smallest existing implementation, and run the narrowest build first. Most of the friction is in the process around the code: formatting, licence metadata for shaded jars, and an RFC for anything that changes a design.

References

Trademarks

Apache XTable (incubating), Apache Hudi, Apache Iceberg, Apache Paimon, Apache Maven 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.

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.