This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new e4d19ae863 [core] Support get config by warehouse in RESTCatalog 
(#5160)
e4d19ae863 is described below

commit e4d19ae863470555fe1f2ef834d54161a943144b
Author: jerry <[email protected]>
AuthorDate: Wed Feb 26 16:13:41 2025 +0800

    [core] Support get config by warehouse in RESTCatalog (#5160)
---
 .../src/main/java/org/apache/paimon/rest/RESTCatalog.java     | 11 +++--------
 .../src/main/java/org/apache/paimon/rest/ResourcePaths.java   |  5 ++++-
 .../test/java/org/apache/paimon/rest/RESTCatalogServer.java   |  2 +-
 .../src/test/java/org/apache/paimon/rest/RESTCatalogTest.java |  9 ---------
 paimon-open-api/rest-catalog-open-api.yaml                    |  7 +++++++
 .../org/apache/paimon/open/api/RESTCatalogController.java     |  8 +++++---
 6 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java 
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
index 3f7846d05f..9f373bd10a 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
@@ -111,7 +111,6 @@ public class RESTCatalog implements Catalog, 
SupportsSnapshots {
     private final ResourcePaths resourcePaths;
     private final CatalogContext context;
     private final boolean dataTokenEnabled;
-    private final FileIO fileIO;
     private final RESTAuthFunction restAuthFunction;
 
     private volatile ScheduledExecutorService refreshExecutor = null;
@@ -126,15 +125,12 @@ public class RESTCatalog implements Catalog, 
SupportsSnapshots {
         Options options = context.options();
         Map<String, String> baseHeaders = Collections.emptyMap();
         if (configRequired) {
-            if (context.options().contains(WAREHOUSE)) {
-                throw new IllegalArgumentException("Can not config warehouse 
in RESTCatalog.");
-            }
-
+            String warehouse = options.get(WAREHOUSE);
             baseHeaders = extractPrefixMap(context.options(), HEADER_PREFIX);
             options =
                     new Options(
                             client.get(
-                                            ResourcePaths.V1_CONFIG,
+                                            ResourcePaths.config(warehouse),
                                             ConfigResponse.class,
                                             new RESTAuthFunction(
                                                     Collections.emptyMap(), 
catalogAuth))
@@ -147,7 +143,6 @@ public class RESTCatalog implements Catalog, 
SupportsSnapshots {
         this.resourcePaths = ResourcePaths.forCatalogProperties(options);
 
         this.dataTokenEnabled = 
options.get(RESTCatalogOptions.DATA_TOKEN_ENABLED);
-        this.fileIO = dataTokenEnabled ? null : fileIOFromOptions(new 
Path(options.get(WAREHOUSE)));
     }
 
     @Override
@@ -290,7 +285,7 @@ public class RESTCatalog implements Catalog, 
SupportsSnapshots {
     private FileIO fileIOForData(Path path, Identifier identifier) {
         return dataTokenEnabled
                 ? new RESTTokenFileIO(catalogLoader(), this, identifier, path)
-                : this.fileIO;
+                : fileIOFromOptions(path);
     }
 
     private FileIO fileIOFromOptions(Path path) {
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java 
b/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
index de6a35d010..50d0a18c08 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
@@ -29,8 +29,11 @@ public class ResourcePaths {
     private static final String V1 = "/v1";
     private static final String DATABASES = "databases";
     private static final String TABLES = "tables";
+    public static final String QUERY_PARAMETER_WAREHOUSE_KEY = "warehouse";
 
-    public static final String V1_CONFIG = V1 + "/config";
+    public static String config(String warehouse) {
+        return String.format("%s/config?%s=%s", V1, 
QUERY_PARAMETER_WAREHOUSE_KEY, warehouse);
+    }
 
     public static ResourcePaths forCatalogProperties(Options options) {
         return new 
ResourcePaths(options.get(RESTCatalogInternalOptions.PREFIX));
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java 
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
index a7938fd00f..564e1e5d8a 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
@@ -123,7 +123,7 @@ public class RESTCatalogServer {
                     if (!("Bearer " + authToken).equals(token)) {
                         return new MockResponse().setResponseCode(401);
                     }
-                    if ("/v1/config".equals(request.getPath())) {
+                    if (request.getPath().startsWith("/v1/config")) {
                         return new MockResponse()
                                 .setResponseCode(200)
                                 .setBody(getConfigBody(warehouse));
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java 
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
index 20e3127a8a..b0cf23202a 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
@@ -78,15 +78,6 @@ class RESTCatalogTest extends CatalogTestBase {
         restCatalogServer.shutdown();
     }
 
-    @Test
-    void testInitFailWhenDefineWarehouse() {
-        Options options = new Options();
-        options.set(CatalogOptions.WAREHOUSE, warehouse);
-        options.set(RESTCatalogOptions.TOKEN_PROVIDER, 
AuthProviderEnum.BEAR.identifier());
-        assertThatThrownBy(() -> new 
RESTCatalog(CatalogContext.create(options)))
-                .isInstanceOf(IllegalArgumentException.class);
-    }
-
     @Test
     void testAuthFail() {
         Options options = new Options();
diff --git a/paimon-open-api/rest-catalog-open-api.yaml 
b/paimon-open-api/rest-catalog-open-api.yaml
index ef136c2359..868a456e5e 100644
--- a/paimon-open-api/rest-catalog-open-api.yaml
+++ b/paimon-open-api/rest-catalog-open-api.yaml
@@ -34,6 +34,13 @@ paths:
         - config
       summary: Get Config
       operationId: getConfig
+      parameters:
+        - name: warehouse
+          in: query
+          required: false
+          schema:
+            type: string
+          description: Warehouse location or identifier to request from the 
service
       responses:
         "200":
           description: OK
diff --git 
a/paimon-open-api/src/main/java/org/apache/paimon/open/api/RESTCatalogController.java
 
b/paimon-open-api/src/main/java/org/apache/paimon/open/api/RESTCatalogController.java
index 059d593c1a..1869170a2c 100644
--- 
a/paimon-open-api/src/main/java/org/apache/paimon/open/api/RESTCatalogController.java
+++ 
b/paimon-open-api/src/main/java/org/apache/paimon/open/api/RESTCatalogController.java
@@ -19,7 +19,6 @@
 package org.apache.paimon.open.api;
 
 import org.apache.paimon.partition.Partition;
-import org.apache.paimon.rest.ResourcePaths;
 import org.apache.paimon.rest.requests.AlterDatabaseRequest;
 import org.apache.paimon.rest.requests.AlterPartitionsRequest;
 import org.apache.paimon.rest.requests.AlterTableRequest;
@@ -64,6 +63,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Arrays;
@@ -73,6 +73,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import static 
org.apache.paimon.rest.ResourcePaths.QUERY_PARAMETER_WAREHOUSE_KEY;
+
 /** RESTCatalog management APIs. */
 @CrossOrigin(origins = "http://localhost:8081";)
 @RestController
@@ -89,8 +91,8 @@ public class RESTCatalogController {
                 responseCode = "500",
                 content = {@Content(schema = @Schema())})
     })
-    @GetMapping(ResourcePaths.V1_CONFIG)
-    public ConfigResponse getConfig() {
+    @GetMapping("/v1/config")
+    public ConfigResponse 
getConfig(@RequestParam(QUERY_PARAMETER_WAREHOUSE_KEY) String warehouse) {
         Map<String, String> defaults = new HashMap<>();
         Map<String, String> overrides = new HashMap<>();
         return new ConfigResponse(defaults, overrides);

Reply via email to