diqiu50 commented on code in PR #13584:
URL: https://github.com/apache/gravitino/pull/13584#discussion_r4131166641


##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalog.java:
##########
@@ -74,6 +74,34 @@ public class GravitinoIcebergCatalog extends BaseCatalog
   @Override
   protected TableCatalog createAndInitSparkCatalog(
       String name, CaseInsensitiveStringMap options, Map<String, String> 
properties) {
+    String catalogBackendName = 
IcebergPropertiesUtils.getCatalogBackendName(properties);
+    Map<String, String> all =
+        buildSparkCatalogProperties(
+            name,
+            options,
+            properties,
+            SparkSession.active().sparkContext().conf(),
+            () -> GravitinoCatalogManager.get().getIcebergRestUri());
+    TableCatalog icebergCatalog = new SparkCatalog();
+    icebergCatalog.initialize(catalogBackendName, new 
CaseInsensitiveStringMap(all));
+    return icebergCatalog;
+  }
+
+  Map<String, String> buildSparkCatalogProperties(
+      String name,
+      CaseInsensitiveStringMap options,
+      Map<String, String> properties,
+      SparkConf sparkConf,
+      Supplier<Optional<String>> endpointDiscovery) {

Review Comment:
   Package-private is intended: the method is the production path called by 
`createAndInitSparkCatalog`, and the reduced visibility also serves as the test 
seam. I'd prefer to keep it as is to keep this fix minimal.



##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalog.java:
##########
@@ -74,6 +74,34 @@ public class GravitinoIcebergCatalog extends BaseCatalog
   @Override
   protected TableCatalog createAndInitSparkCatalog(
       String name, CaseInsensitiveStringMap options, Map<String, String> 
properties) {
+    String catalogBackendName = 
IcebergPropertiesUtils.getCatalogBackendName(properties);
+    Map<String, String> all =
+        buildSparkCatalogProperties(
+            name,
+            options,
+            properties,
+            SparkSession.active().sparkContext().conf(),
+            () -> GravitinoCatalogManager.get().getIcebergRestUri());
+    TableCatalog icebergCatalog = new SparkCatalog();
+    icebergCatalog.initialize(catalogBackendName, new 
CaseInsensitiveStringMap(all));
+    return icebergCatalog;
+  }
+
+  Map<String, String> buildSparkCatalogProperties(
+      String name,
+      CaseInsensitiveStringMap options,
+      Map<String, String> properties,
+      SparkConf sparkConf,
+      Supplier<Optional<String>> endpointDiscovery) {
+    Optional<String> icebergRestUri =
+        resolveIcebergRestUri(properties, key -> sparkConf.get(key, null), 
endpointDiscovery);
+    if (icebergRestUri.isPresent()) {

Review Comment:
   Yes, this is intended. For a routing-eligible catalog, the routing error 
names the actual misconfiguration and how to fall back, while the driver 
`ClassNotFoundException` pointed at a class the routed client never uses.



##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/iceberg/TestGravitinoIcebergCatalogRestRouting.java:
##########
@@ -226,6 +244,42 @@ void 
testAutoRoutedRestClientConfigStripsPrefixFromRealSparkConf() {
     Assertions.assertEquals("admin", result.get("rest.auth.basic.username"));
   }
 
+  @Test
+  void testRoutedCatalogDoesNotRequireBackendJdbcDriver() {
+    SparkConf sparkConf = new SparkConf(false);
+    sparkConf.set(GravitinoSparkConfig.GRAVITINO_ICEBERG_REST_URI, 
"http://manual/iceberg";);
+
+    Map<String, String> result =
+        new GravitinoIcebergCatalog()
+            .buildSparkCatalogProperties(
+                "iceberg_jdbc",
+                CaseInsensitiveStringMap.empty(),
+                jdbcPropertiesWithMissingDriver(),
+                sparkConf,
+                Optional::empty);
+
+    Assertions.assertEquals("http://manual/iceberg";, 
result.get(IcebergConstants.URI));
+  }
+
+  @Test
+  void testLegacyCatalogPreloadsBackendJdbcDriver() {

Review Comment:
   Agreed that the rest of the legacy branch is not covered here. It is 
unchanged by this PR, so I'd like to keep the tests focused on the driver 
preload ordering and leave broader legacy coverage for a follow-up.



-- 
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