How do I set up Unity Catalog OSS with Spark?
Summary
- To use Unity Catalog OSS with Apache Spark, run a Unity Catalog server, then start Spark with the Unity Catalog Spark connector and a matching Delta Spark build, and register a catalog with
io.unitycatalog.spark.UCSingleCatalog. - The connector is built per Spark minor version. For Unity Catalog 0.7.0 the artifacts are
unitycatalog-spark_4.0_2.13,_4.1_2.13and_4.2_2.13, all for Scala 2.13, and catalog-managed tables need Delta Spark 4.3.0 or later. - Always set an authentication type, even on a local server with authorization disabled, or the first query fails with "Required configuration key 'type' is missing or empty."
- The same connector can connect open-source Spark to Unity Catalog on Databricks through the Unity REST API, once a metastore admin enables external data access and grants EXTERNAL USE SCHEMA.
How do I set up Unity Catalog OSS with Spark?
Start a Unity Catalog server, then launch Spark with two packages: the Unity Catalog Spark connector built for your Spark minor version and a Delta Spark release for the same Spark version. Register the catalog with spark.sql.catalog.<name> set to io.unitycatalog.spark.UCSingleCatalog, point .uri at the server, and set an authentication type. The steps below use Unity Catalog 0.7.0 and PySpark 4.1, the versions the project's own docs test against.
Unity Catalog OSS is an open catalog for tables, volumes, functions and models, released under the Apache 2.0 license and hosted by the LF AI & Data Foundation. Apache Spark reaches it through the Unity Catalog Spark connector, so Spark SQL can address catalog.schema.table names and read and write the tables the catalog holds. Delta Spark handles the table format.
Step 1: Start a Unity Catalog server
The quickest path is the docs' Docker Compose environment, which needs Docker with Compose v2:
curl -fsSL https://docs.unitycatalog.io/env/unitycatalog.tar.gz | tar -xz
cd uc-docs-env/unitycatalog && docker compose up -d --wait
export UNITY_CATALOG_URL=http://localhost:8080/api/2.1/unity-catalog
The server listens on http://localhost:8080 with a sample catalog named unity. Authorization is disabled and metadata lives in the container, so this setup is for one developer only. To run from source instead, point JAVA_HOME at JDK 17, compile with build/sbt package, and run bin/start-uc-server.
Step 2: Pick matching versions
| Spark | Unity Catalog connector (0.7.0) | Delta Spark |
|---|---|---|
| 4.0 | io.unitycatalog:unitycatalog-spark_4.0_2.13:0.7.0 |
io.delta:delta-spark_4.0_2.13:4.3.1 |
| 4.1 | io.unitycatalog:unitycatalog-spark_4.1_2.13:0.7.0 |
io.delta:delta-spark_4.1_2.13:4.3.1 |
| 4.2 | io.unitycatalog:unitycatalog-spark_4.2_2.13:0.7.0 |
io.delta:delta-spark_4.2_2.13:4.4.1 |
With a Delta Spark release older than 4.3.0, the connector quietly skips the Delta API and catalog-managed tables don't work. Releases before 0.5.0 shipped a single unitycatalog-spark_2.13 artifact.
Step 3: Configure the Spark session
The docs' prerequisites for this step include Java 17 and uv. This session registers a catalog named retail; repeat the spark.sql.catalog.<name> block for each catalog you use:
from pyspark.sql import SparkSession
spark = (
SparkSession.builder.appName("managed-orders")
.config("spark.jars.packages",
"io.unitycatalog:unitycatalog-spark_4.1_2.13:0.7.0,"
"io.delta:delta-spark_4.1_2.13:4.3.1")
.config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension")
.config("spark.sql.catalog.spark_catalog",
"org.apache.spark.sql.delta.catalog.DeltaCatalog")
.config("spark.sql.catalog.retail", "io.unitycatalog.spark.UCSingleCatalog")
.config("spark.sql.catalog.retail.uri", "http://localhost:8080")
.config("spark.sql.catalog.retail.auth.type", "static")
.config("spark.sql.catalog.retail.auth.token", "not-used")
.config("spark.sql.defaultCatalog", "retail")
.getOrCreate()
)
The uri is the server's base URL, without /api/2.1/unity-catalog. The same keys work as --conf options for spark-submit, spark-sql and pyspark, with --packages in place of spark.jars.packages. For OAuth client credentials, set auth.type to oauth with auth.oauth.uri, auth.oauth.clientId and auth.oauth.clientSecret, and read secrets from the environment rather than source code.
Step 4: Create and query a managed table
A managed table needs a catalog with a storage root. The project's tutorial creates retail with the unitycatalog-client Python package (CreateCatalog(name="retail", storage_root=...)). Then leave out LOCATION, and Unity Catalog chooses where the files live:
spark.sql("CREATE SCHEMA sales")
spark.sql("""
CREATE TABLE sales.orders (
order_id BIGINT,
customer STRING,
amount DECIMAL(10, 2)
) USING DELTA
""")
spark.sql("INSERT INTO sales.orders VALUES (1, 'ada', 9.50)")
spark.table("sales.orders").show()
The connector marks the table delta.feature.catalogManaged, which tells every Delta client that the catalog, not the files, has the final say on the table's latest version. For Iceberg tables, Unity Catalog 0.7.0 also exposes an Iceberg REST catalog at /api/2.1/unity-catalog/iceberg, which Spark can use through Iceberg's own SparkCatalog with type=rest and no Unity Catalog connector.
Common setup errors
| Symptom | Likely cause | Fix |
|---|---|---|
Required configuration key 'type' is missing or empty |
No authentication type set | Set auth.type (static or oauth) |
| Catalog-managed tables don't work | Delta Spark older than 4.3.0 | Upgrade Delta Spark to match the table above |
| Sample tables list but can't be read | Their files live inside the server container | Create tables under a storage root both Spark and the server can reach |
| Packages must come from an internal Maven mirror | Spark resolves spark.jars.packages from its default repository |
Add spark.jars.repositories pointing at your mirror |
How Databricks approaches Unity Catalog with Spark
Unity Catalog on Databricks is managed, and open-source Spark can reach it with the same connector through the Unity REST API. A metastore admin enables External data access on the metastore, and the principal needs the EXTERNAL USE SCHEMA privilege, which ALL PRIVILEGES doesn't include. Set uri to the workspace URL and authenticate with a personal access token or OAuth machine-to-machine credentials (token endpoint https://<workspace-url>/oidc/v1/token). The Databricks docs list Unity Catalog Spark client 0.5.0 or above, Spark 4.0 or 4.1, and Delta Spark 4.3.0 or above. External clients can read managed tables and create, read and write external Delta tables. Iceberg clients connect through the Iceberg REST catalog.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.