Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

7.4 KB
Raw Blame

title: "Spark Lakehouse REST Catalog Discovery" slug: "/spark-connector/spark-rest-catalog-discovery" keyword: "spark lakehouse REST catalog discovery Lance" license: "This software is licensed under the Apache License version 2."

Overview

The Gravitino Spark connector can discover the catalogs served by a lakehouse REST server and register them in Spark automatically. A Spark session only needs the discovery plugin and one REST server URI per lakehouse format. Catalogs added to the server become available after the Spark session is restarted.

Lance REST discovery is supported. The corresponding Iceberg REST provider is planned separately.

Requirements

Add both of the following artifacts to the Spark application classpath:

  • The Gravitino Spark connector runtime matching the Spark version.
  • A compatible lance-spark-bundle containing org.lance.spark.LanceNamespaceSparkCatalog and org.lance.spark.extensions.LanceSparkSessionExtensions.

The discovery provider uses the Lance Namespace client shipped in the Lance Spark bundle. Gravitino does not package another copy of that client in its Spark connector runtime.

Configuration

Configure the discovery plugin and the Lance REST server URI:

spark.plugins=org.apache.gravitino.spark.connector.plugin.restcatalog.GravitinoLakehouseRESTDiscoveryPlugin
spark.sql.gravitino.lanceREST.uri=http://127.0.0.1:9101/lance

When the regular Gravitino Spark plugin is also required, the discovery plugin must be listed first:

spark.plugins=org.apache.gravitino.spark.connector.plugin.restcatalog.GravitinoLakehouseRESTDiscoveryPlugin,\
              org.apache.gravitino.spark.connector.plugin.GravitinoSparkPlugin

Spark startup fails if the order is reversed. Initializing discovery first allows the plugin to distinguish user-written catalog configuration from entries generated by the regular plugin.

For every catalog discovered from the Lance REST server, the plugin generates:

spark.sql.catalog.<catalogName>=org.lance.spark.LanceNamespaceSparkCatalog
spark.sql.catalog.<catalogName>.impl=rest
spark.sql.catalog.<catalogName>.uri=<spark.sql.gravitino.lanceREST.uri>
spark.sql.catalog.<catalogName>.parent=<catalogName>

It also adds org.lance.spark.extensions.LanceSparkSessionExtensions to spark.sql.extensions, without adding a duplicate when the extension is already configured.

Catalog properties

Properties under the following prefix are copied to every discovered Lance catalog:

spark.sql.gravitino.lanceREST.catalogProperties.<key>=<value>

Configuration precedence, from highest to lowest, is:

  1. A user-defined spark.sql.catalog.<name> owns the complete catalog name and disables automatic registration for that discovered name.
  2. A user-defined spark.sql.catalog.<name>.<key> overrides the value for that catalog.
  3. Provider-generated routing properties such as impl, uri, and parent.
  4. Global lanceREST.catalogProperties.<key> defaults.

The discovery provider does not generate lance.storage.* configuration. Storage options continue to come from the Lance REST service or from explicit Spark catalog properties.

Set spark.sql.gravitino.lanceREST.catalogProperties.namespaceDelimiter when the Lance REST server uses a namespace delimiter other than the default $. The property is used for the discovery request and is also copied to each discovered catalog.

User identity

When spark.sql.gravitino.authType is simple (the default), the discovery plugin uses SparkContext.sparkUser() as the Lance user. It sends an HTTP Basic header with the UTF-8 encoded value <user>:unused for discovery and copies it to each automatically registered Lance catalog. The password is a placeholder. Usernames containing a colon require explicit credentials because HTTP Basic uses the colon to separate the username from the password.

Set spark.sql.gravitino.lanceREST.catalogProperties.headers.Authorization to use explicit credentials for discovery and as the default for registered catalogs. A per-catalog spark.sql.catalog.<name>.headers.Authorization overrides the global header for that catalog's operations. Header names are case-insensitive. Within each configuration scope, equivalent keys with identical values are collapsed and conflicting values are rejected.

The plugin generates a header only when authType is simple. This setting selects the default for the Lance endpoint independently of Hadoop security, so a Kerberos-enabled Spark application can use it to access an independent simple-auth Lance REST server. Configure explicit credentials when the Lance endpoint uses a different authentication scheme. Manually registered catalogs require their own configuration.

Upgrading existing jobs

Default-simple jobs now send a Basic header even if they previously sent no authentication header. In auxiliary mode, requests that previously fell back to the Lance REST service user may now execute as the Spark user. Before upgrading, register that user and grant the permissions needed for discovery and subsequent operations. Missing grants can cause HTTP 403 responses, and objects created by the job may have a different creator or owner. To keep running as the previous service user, set the global Authorization header to credentials that the Lance endpoint accepts for that service user. For example, if the endpoint accepts Simple authentication, use a Basic header for the service user's name.

A standalone Lance REST server may reject the generated Basic header with HTTP 401 if it uses another scheme. Configure the server's expected Authorization header explicitly. Standalone servers continue to use their configured service credentials to access the Gravitino backend.

Registration policy

By default, every discovered catalog is registered under its discovered name. To filter or rename catalogs, implement org.apache.gravitino.spark.connector.plugin.restcatalog.CatalogRegistrationPolicy with a public no-argument constructor and configure its class name:

spark.sql.gravitino.REST.registrationPolicy=com.example.MyCatalogRegistrationPolicy

The policy receives the format token (lance) and the discovered catalog name. A renamed Spark catalog still uses the discovered name as its parent, so REST routing remains server-authoritative. Spark startup fails if a policy returns a blank name, an invalid identifier, a duplicate name, or a name already owned by user configuration.

Gravitino accepts catalog names that Spark cannot reference unquoted, such as names containing a hyphen. Without a configured policy, such a catalog is logged at WARN and skipped rather than failing Spark startup, so one unusable name does not prevent the session from starting. Configure a policy to rename it to an identifier Spark accepts.

Limitations

  • Each format supports one REST server URI per Spark session.
  • Discovery is a startup dependency with no fallback. If the REST server is unreachable while the driver starts, the plugin fails and the whole Spark session fails to start.
  • Automatic Lance discovery does not support authenticated REST listing. Catalog properties are applied to generated Spark catalogs but are not used to authenticate the discovery request.
  • Discovery runs only during driver startup; restart the Spark session to observe catalog additions or removals.
  • A catalog registered by Spark is loaded lazily, so SHOW CATALOGS may not display it until it has been referenced.