FANNG1 commented on code in PR #11280:
URL: https://github.com/apache/gravitino/pull/11280#discussion_r3463950089


##########
design-docs/spark-rest-catalog-registration.md:
##########
@@ -0,0 +1,315 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+# Design: Spark REST Catalog Automatic Registration
+
+## Problem
+
+Spark users can already connect to Gravitino with a small amount of 
configuration:
+
+```text
+spark.plugins=org.apache.gravitino.spark.connector.plugin.GravitinoSparkPlugin
+spark.sql.gravitino.uri=http://127.0.0.1:8090
+spark.sql.gravitino.metalake=test
+```
+
+However, when users want Spark to access Iceberg or Lance through their REST 
protocols, they still
+need to hand-write Spark catalog configuration for each catalog:
+
+```text
+spark.sql.catalog.iceberg_prod=org.apache.iceberg.spark.SparkCatalog
+spark.sql.catalog.iceberg_prod.type=rest
+spark.sql.catalog.iceberg_prod.uri=http://127.0.0.1:9001/iceberg/
+spark.sql.catalog.iceberg_prod.warehouse=iceberg_prod
+
+spark.sql.catalog.lance_vectors=org.lance.spark.LanceNamespaceSparkCatalog
+spark.sql.catalog.lance_vectors.impl=rest
+spark.sql.catalog.lance_vectors.uri=http://127.0.0.1:9101/lance
+spark.sql.catalog.lance_vectors.parent=lance_vectors
+```
+
+This duplicates information already managed by Gravitino and forces users to 
update Spark
+configuration whenever Gravitino catalogs change.
+
+## Goal
+
+The Gravitino Spark connector should register Spark REST catalogs 
automatically for supported
+Gravitino catalogs. The user-facing goal is simple: Gravitino remains the 
catalog inventory, and
+Spark derives the Iceberg/Lance REST catalog configuration from that inventory.
+
+V1 scope is Spark only.
+
+Non-goals in V1:
+
+1. Do not introduce a generic access-mode framework.
+2. Do not introduce a dedicated Lance catalog provider.
+3. Do not change the Gravitino REST API contract.
+
+## Supported Catalogs
+
+This design supports the following Gravitino catalog providers in V1:
+
+| Gravitino catalog provider | Extra catalog constraints    | Default Spark 
registration                | REST catalog registration                         
                |
+|----------------------------|------------------------------|-------------------------------------------|-------------------------------------------------------------------|
+| `lakehouse-iceberg`        | None                         | Existing 
Gravitino Spark catalog behavior | Enabled only when 
`spark.sql.gravitino.iceberg.enableRestAccess=true` |
+| `lakehouse-generic`        | Catalog-level `format=lance` | Existing 
behavior                         | Enabled only when 
`spark.sql.gravitino.lance.enableRestAccess=true` |
+| Other providers            | None                         | Existing 
behavior                         | Not supported in V1                          
                     |
+
+For `lakehouse-generic + format=lance`, `format=lance` is interpreted as a 
catalog-level marker only
+for Lance REST catalog registration. This does not change the existing 
behavior of other generic
+catalogs. When the marker is present, the catalog is treated as a Lance 
catalog, and tables under
+this catalog must be Lance tables. Generic catalogs without catalog-level 
`format=lance` are ignored
+by Lance REST catalog registration. Because there is no Lance Gravitino Spark 
catalog in V1, Lance
+only supports REST catalog registration.
+
+## Spark Configuration
+
+Iceberg REST catalog registration is disabled by default to preserve existing 
Gravitino Spark
+connector behavior. Users enable it with:
+
+```text
+spark.sql.gravitino.iceberg.enableRestAccess=true
+```
+
+Lance REST catalog registration is disabled by default because registration 
needs to load Lance
+Spark catalog and extension classes, and users may not have the Lance Spark 
runtime on the
+classpath. Users explicitly enable Lance REST access with:
+
+```text
+spark.sql.gravitino.lance.enableRestAccess=true
+```
+
+When Lance REST access is enabled, the Spark connector registers REST catalogs 
for
+`lakehouse-generic + format=lance` catalogs.
+
+Optional REST service URI overrides:
+
+| Configuration | Default |
+|---------------|---------|
+| `spark.sql.gravitino.iceberg.restUri` | Inferred from 
`spark.sql.gravitino.uri` |
+| `spark.sql.gravitino.lance.restUri` | Inferred from 
`spark.sql.gravitino.uri` |
+
+The Iceberg switch applies to all Gravitino Iceberg catalogs visible to the 
Spark connector in V1.
+Per-catalog REST registration override is future work.

Review Comment:
   Good point. I will add a before/after example to make the behavior clearer.
   
   Assume there is a Gravitino Iceberg catalog:
   
   ```text
   name = iceberg_jdbc
   type = RELATIONAL
   provider = lakehouse-iceberg
   
   catalog-backend = jdbc
   uri = jdbc:postgresql://127.0.0.1:5432/iceberg
   warehouse = s3://warehouse/iceberg_jdbc
   ```
   
   Also assume the Gravitino Iceberg REST server exposes a catalog named 
`iceberg_jdbc`, and its backend configuration is consistent with this Gravitino 
Iceberg catalog.
   
   This is naturally satisfied when the Iceberg REST server uses the dynamic 
config provider, because it loads catalog configuration from Gravitino and 
exposes catalogs by Gravitino catalog name. This is the recommended scenario. 
If the static config provider is used, users must manually keep the REST server 
catalog name and backend configuration consistent with the Gravitino catalog.
   
   Before enabling this option, Spark keeps the existing Gravitino Spark 
connector behavior:
   
   ```text
   spark.sql.gravitino.iceberg.enableRestAccess=false
   ```
   
   Catalog metadata access goes through the Gravitino REST protocol. For 
Iceberg table access, the Iceberg metadata used by the IO path, such as table 
metadata and manifest metadata, is still loaded through the Iceberg JDBC 
catalog implementation behind the Gravitino Iceberg catalog.
   
   After enabling this option:
   
   ```text
   spark.sql.gravitino.iceberg.enableRestAccess=true
   spark.sql.gravitino.iceberg.restUri=http://127.0.0.1:9001/iceberg/
   ```
   
   The Spark connector registers a Spark Iceberg REST catalog using the 
Gravitino catalog name:
   
   ```text
   spark.sql.catalog.iceberg_jdbc=org.apache.iceberg.spark.SparkCatalog
   spark.sql.catalog.iceberg_jdbc.type=rest
   spark.sql.catalog.iceberg_jdbc.uri=http://127.0.0.1:9001/iceberg/
   spark.sql.catalog.iceberg_jdbc.warehouse=iceberg_jdbc
   ```
   
   Then Spark accesses Iceberg metadata through the Iceberg REST protocol. The 
Spark side no longer needs direct exposure to the Iceberg JDBC catalog 
configuration; it only needs the Iceberg REST endpoint and the Gravitino 
catalog name. The backend catalog configuration is owned by the Iceberg REST 
server.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to