All posts

Apache XTable CatalogSync: register tables in Hive and Glue

One RunCatalogSync run converts a table and registers it in every catalog you list. Its create, replace and refresh logic, the config keys, a real Hive Metastore run read back from Trino, and why a down metastore still exits 0.

7 min read Lakehouse

TL;DR

RunCatalogSync does two jobs in one run: it converts the table to each target format, then registers each target in every catalog you list.

  • Catalog types are STORAGE, GLUE and HMS. STORAGE means “no catalog, just a path”, and it is only useful as a source.
  • For each target catalog the code creates the database if it is missing, creates the table if it is missing, re-creates it if the storage location changed, and otherwise refreshes it.
  • Each catalog is its own try block. One failing catalog is logged and the run continues, and the process still exits 0.
  • The Hive Metastore client does not run on the bundled jar alone in this release. It needs Hive classes added to the classpath, and registering a Delta table also needs Delta’s Hive storage handler.
  • A registered table is only as good as its location. A local path fails in a metastore that cannot reach it.

A converted table that no engine can find by name is invisible. Registration fixes that, and RunCatalogSync automates it for many tables. Its behaviour below is read from the 0.5.0-incubating source and was run against a Hive Metastore, with Trino reading the result. Glue was read from the code only.

RunCatalogSync reads a source, writes the target format's metadata, then CatalogSync registers each target in every listed catalog: it creates a missing database or table, re-creates a table whose location changed, and otherwise refreshes it

TableFormatSync and CatalogSync

They answer different questions. RunSync writes Iceberg, Delta or Hudi metadata beside the data. A catalog tells an engine where a table is, under what name. RunCatalogSync is the one command that does both: syncTableAcrossCatalogs builds the target tables and runs the format sync, then hands each result to CatalogSync.syncTable. The architecture post lays out why they are separate mechanisms.

The config

sourceCatalog:
  catalogId: "storage"
  catalogType: "STORAGE"
  catalogProperties: {}
targetCatalogs:
  - catalogId: "hms"
    catalogSyncClientImpl: "org.apache.xtable.hms.HMSCatalogSyncClient"
    catalogProperties:
      externalCatalog.hms.serverUrl: "thrift://hive-metastore:9083"
datasets:
  - sourceCatalogTableIdentifier:
      storageIdentifier:
        tableBasePath: s3a://warehouse/xtable_series/trips
        tableName: trips
        partitionSpec: city_id:VALUE
        tableFormat: "HUDI"
    targetCatalogTableIdentifiers:
      - catalogId: "hms"
        tableFormat: "ICEBERG"
        tableIdentifier:
          hierarchicalId: "xtable_series.trips"

An ExternalCatalogConfig has a catalogId, a catalogType, a catalogSyncClientImpl for a target, a catalogConversionSourceImpl for a source, and a map of catalogProperties. The three types are STORAGE, GLUE and HMS. Both HMSCatalogConversionSource and GlueCatalogConversionSource exist, so a catalog can be the source of the table as well as the target. A type outside those three fails with catalogType is not yet supported: <type>.

The three catalog types: STORAGE is only a path, HMS and GLUE have sync clients and conversion sources

Clients are found with ServiceLoader, like format targets. The xtable-hive-metastore module registers HMSCatalogSyncClient and HMSCatalogConversionSource, and xtable-aws provides the Glue ones.

Keys for each catalog

Catalog Property Meaning
HMS externalCatalog.hms.serverUrl The Thrift URL
HMS externalCatalog.hms.schema_string_length_thresh Schema string length limit
HMS externalCatalog.hms.partition_extractor_class How partitions are extracted
HMS externalCatalog.hms.max_partitions_per_request Batch size
Glue externalCatalog.glue.region AWS region
Glue externalCatalog.glue.catalogId The Glue catalog id
Glue externalCatalog.glue.credentialsProviderClass A provider class, with its own settings under externalCatalog.glue.credentials.provider. such as accessKey and secretAccessKey
Glue externalCatalog.glue.schema_string_length_thresh, partition_extractor_class, max_partitions_per_request The same three as HMS

Glue credentials go through those properties. RunCatalogSync has only three options, --catalogSyncConfig, --hadoopConfig and --convertersConfig, plus --help, so a credentials flag mentioned in some guides does not exist in 0.5.0.

What CatalogSync does for each catalog

CatalogSync.syncTable runs these steps per client:

  1. If the database is missing, create it.
  2. Look up the table and read its storage location.
  3. If the table does not exist, create it.
  4. If it exists with a different location from XTable’s base path, log StorageDescriptor location changed from ... to ..., re-creating table and replace it. The code comment gives two causes: someone created it by hand with another location, or the base path moved.
  5. Otherwise refresh it.

Each client sits in its own try. A failure is logged as Catalog sync failed for table ... using catalogSync <class> and recorded as an error status, and the next catalog is tried. A success logs Catalog sync is successful for table .... Step 4 is worth knowing about before you point XTable at a catalog with tables you created yourself: a location mismatch replaces the table.

The decision for each catalog: create a missing database, create a missing table, replace a table whose location changed, otherwise refresh

Running it

java -cp "$XTABLE_JAR" org.apache.xtable.utilities.RunCatalogSync \
  --catalogSyncConfig trips_catalog.yaml --hadoopConfig s3-site.xml

Only RunSync is the bundled jar’s main class, so this one needs -cp and the class name.

The Hive classes are not bundled

Run exactly like that and the conversion succeeds, then registration stops with NoClassDefFoundError: org/apache/hadoop/hive/metastore/api/NoSuchObjectException. The release dropped unused Hive dependencies from the metastore module. For a Hive Metastore, these jars after the XTable jar made it work:

java -cp "$XTABLE_JAR:hive-exec-3.1.3.jar:hive-metastore-3.1.3.jar:libthrift-0.12.0.jar:libfb303-0.9.3.jar:calcite-core-1.16.0.jar:calcite-linq4j-1.16.0.jar:iceberg-hive-runtime-1.7.2.jar" \
  org.apache.xtable.utilities.RunCatalogSync --catalogSyncConfig trips_catalog.yaml --hadoopConfig s3-site.xml

The Delta builder sets io.delta.hive.DeltaStorageHandler on the table, so a Delta target needs delta-hive and delta-standalone as well. A Delta table did not register in these runs even after adding both and a Scala shapeless jar, so treat Delta through Hive Metastore as unproven in 0.5.0 and use CREATE TABLE ... USING DELTA LOCATION from Spark instead.

What a run looks like

A three-row Hudi table on MinIO, RunCatalogSync with an Iceberg target in Hive Metastore, run twice. Both runs exited 0. Trino then read the registered table:

"nyc","1"
"sf","2"

The conversion and the registration happened in one command, and the second run refreshed the table. With the Hive jars on the classpath XTable printed almost no log lines at all, because log4j2’s configuration failed to initialise (Unrecognized format specifier from StatusLogger). The registered table was the only evidence of success, so verify in the catalog, not the log.

Failures

Symptom Cause
MetaException: file:/work/data/trips_rt is not a directory or unable to create one The table’s location was a local path the metastore server cannot reach. Use a shared path such as s3a://
UnknownHostException inside Unable to instantiate SessionHiveMetaStoreClient The serverUrl host does not resolve
NoClassDefFoundError: org/apache/hadoop/hive/metastore/api/NoSuchObjectException The Hive jars are not on the classpath
catalogType is not yet supported: <type> The type is not STORAGE, GLUE or HMS
A table replaced unexpectedly Its location differed from XTable’s base path

The first two were run. With an unreachable metastore URL, RunCatalogSync logged the UnknownHostException and exited 0, because main catches the exception per dataset the way RunSync does. An orchestrator must check the log or the catalog, not the exit code.

Security and operations

The sync needs credentials for each catalog and write access to the storage location, since converting writes metadata into the table path. HMS needs to accept createDatabase, createTable and table updates, and Glue needs the matching IAM actions. The Glue permissions come from the code’s calls and were not tested. Registering a table in two catalogs is two separate operations with no shared transaction, so one can succeed while the other fails.

Checked against the source

Claim Where
Create, replace and refresh logic, per-client try block, log messages CatalogSync.syncTable, syncCatalog
Catalog types and the error for an unknown one CatalogType, CatalogConversionFactory
Config class fields ExternalCatalogConfig
HMS and Glue property keys HMSCatalogConfig, GlueCatalogConfig
RunCatalogSync options and per-dataset catch RunCatalogSync
Delta storage handler DeltaHMSCatalogTableBuilder
Clients registered with ServiceLoader META-INF/services in xtable-hive-metastore

The Hive Metastore run, the second run and the Trino read are from a Docker stack with a real metastore and MinIO. The Glue client was not run.

Key takeaways

Registration is a separate step with separate failures, and RunCatalogSync folds it into the conversion. Learn its three-way decision (create, replace, refresh), put the Hive jars on the classpath yourself, give tables a location the metastore can reach, and check the catalog after every run because a down metastore does not change the exit code.

References

Trademarks

Apache XTable (incubating), Apache Hive, Apache Hudi, Apache Iceberg 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. AWS Glue is a trademark of Amazon. 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.