MgjLLL commented on code in PR #8823:
URL: https://github.com/apache/paimon/pull/8823#discussion_r3672843715


##########
paimon-core/src/main/java/org/apache/paimon/table/CatalogEnvironment.java:
##########
@@ -196,6 +205,43 @@ public CatalogContext catalogContext() {
         return catalogContext;
     }
 
+    /**
+     * Returns a context for loading tables referenced while reading this 
table.
+     *
+     * <p>For REST catalogs, the outermost table identifier is attached as an 
optional request
+     * header. A context which already carries the header is returned 
unchanged so nested
+     * dependencies preserve the original table.
+     */
+    @Nullable
+    CatalogContext dependencyReadContext() {
+        if (identifier == null || catalogContext == null) {
+            return catalogContext;
+        }
+
+        boolean restCatalog =
+                catalogLoader instanceof RESTCatalogLoader
+                        || RESTCatalogFactory.IDENTIFIER.equals(
+                                catalogContext.options().get(METASTORE));
+        if (!restCatalog) {
+            return catalogContext;
+        }
+
+        Options options = catalogContext.options();
+        if (options.containsKey(READ_VIA_OPTION)) {
+            return catalogContext;
+        }
+
+        Options dependencyOptions = new Options(options.toMap());
+        dependencyOptions.set(METASTORE, RESTCatalogFactory.IDENTIFIER);

Review Comment:
    `dependencyReadContext()` currently unconditionally sets `metastore` to the 
built-in REST Catalog identifier:
    ```java
     dependencyOptions.set(METASTORE, RESTCatalogFactory.IDENTIFIER);
   ```
   This may break custom REST Catalog implementations whose loaders extend 
RESTCatalogLoader.
   For example, customer uses a custom REST Catalog factory:
    ```java
   metastore=paimon-test
   ```
     Its Catalog loader extends RESTCatalogLoader, so it is recognized as a 
REST Catalog by the current logic. However, after metastore is overwritten with 
rest, the following call:
    ```java
   CatalogFactory.createCatalog(dependencyContext)
   ```
     will create the built-in RESTCatalog instead of the original custom 
TestRestCatalog.
   
   Could we preserve an existing metastore identifier and only fall back to the 
built-in REST identifier when it is absent? for example:
    ```java
     if (!dependencyOptions.containsKey(METASTORE)) {
         dependencyOptions.set(
                 METASTORE,
                 RESTCatalogFactory.IDENTIFIER);
     }
   ```



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