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 b105ac835f [rest] Introduce register api definition in rest (#5859)
b105ac835f is described below
commit b105ac835f4b21a6d2c5696a025cf3074766aedd
Author: kevin <[email protected]>
AuthorDate: Fri Jul 11 09:57:50 2025 +0800
[rest] Introduce register api definition in rest (#5859)
---
docs/static/rest-catalog-open-api.yaml | 42 +++++++++++++++
.../main/java/org/apache/paimon/rest/RESTApi.java | 8 +++
.../java/org/apache/paimon/rest/ResourcePaths.java | 5 ++
.../paimon/rest/requests/RegisterTableRequest.java | 60 ++++++++++++++++++++++
.../java/org/apache/paimon/catalog/Catalog.java | 12 +++++
.../org/apache/paimon/catalog/DelegateCatalog.java | 6 +++
.../java/org/apache/paimon/rest/RESTCatalog.java | 16 ++++++
7 files changed, 149 insertions(+)
diff --git a/docs/static/rest-catalog-open-api.yaml
b/docs/static/rest-catalog-open-api.yaml
index 8e2202729a..0b85c56fcb 100644
--- a/docs/static/rest-catalog-open-api.yaml
+++ b/docs/static/rest-catalog-open-api.yaml
@@ -206,6 +206,41 @@ paths:
$ref: '#/components/responses/DatabaseNotExistErrorResponse'
"500":
$ref: '#/components/responses/ServerErrorResponse'
+ /v1/{prefix}/databases/{database}/register:
+ post:
+ tags:
+ - table
+ summary: Register table
+ operationId: RegisterTable
+ parameters:
+ - name: prefix
+ in: path
+ required: true
+ schema:
+ type: string
+ - name: database
+ in: path
+ required: true
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RegisterTableRequest'
+ responses:
+ "200":
+ description: Success, no content
+ "400":
+ $ref: '#/components/responses/BadRequestErrorResponse'
+ "401":
+ $ref: '#/components/responses/UnauthorizedErrorResponse'
+ "404":
+ $ref: '#/components/responses/DatabaseNotExistErrorResponse'
+ "409":
+ $ref: '#/components/responses/TableAlreadyExistErrorResponse'
+ "500":
+ $ref: '#/components/responses/ServerErrorResponse'
/v1/{prefix}/databases/{database}/tables:
get:
tags:
@@ -1929,6 +1964,13 @@ components:
$ref: '#/components/schemas/Identifier'
schema:
$ref: '#/components/schemas/Schema'
+ RegisterTableRequest:
+ type: object
+ properties:
+ identifier:
+ $ref: '#/components/schemas/Identifier'
+ path:
+ type: string
CreateViewRequest:
type: object
properties:
diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
index 5af953eb85..08ed9f93d2 100644
--- a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
+++ b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
@@ -45,6 +45,7 @@ import org.apache.paimon.rest.requests.CreateTableRequest;
import org.apache.paimon.rest.requests.CreateViewRequest;
import org.apache.paimon.rest.requests.ForwardBranchRequest;
import org.apache.paimon.rest.requests.MarkDonePartitionsRequest;
+import org.apache.paimon.rest.requests.RegisterTableRequest;
import org.apache.paimon.rest.requests.RenameTableRequest;
import org.apache.paimon.rest.requests.RollbackTableRequest;
import org.apache.paimon.rest.responses.AlterDatabaseResponse;
@@ -677,6 +678,13 @@ public class RESTApi {
restAuthFunction);
}
+ public void registerTable(Identifier identifier, String path) {
+ client.post(
+ resourcePaths.registerTable(identifier.getDatabaseName()),
+ new RegisterTableRequest(identifier, path),
+ restAuthFunction);
+ }
+
/**
* Mark done partitions for table.
*
diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java
b/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java
index 25f7ab9a2d..7bf67eba40 100644
--- a/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java
+++ b/paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java
@@ -37,6 +37,7 @@ public class ResourcePaths {
protected static final String TABLE_DETAILS = "table-details";
protected static final String VIEW_DETAILS = "view-details";
protected static final String ROLLBACK = "rollback";
+ protected static final String REGISTER = "register";
protected static final String FUNCTIONS = "functions";
protected static final String FUNCTION_DETAILS = "function-details";
@@ -112,6 +113,10 @@ public class ResourcePaths {
ROLLBACK);
}
+ public String registerTable(String databaseName) {
+ return SLASH.join(V1, prefix, DATABASES, encodeString(databaseName),
REGISTER);
+ }
+
public String tableToken(String databaseName, String objectName) {
return SLASH.join(
V1,
diff --git
a/paimon-api/src/main/java/org/apache/paimon/rest/requests/RegisterTableRequest.java
b/paimon-api/src/main/java/org/apache/paimon/rest/requests/RegisterTableRequest.java
new file mode 100644
index 0000000000..2fc9c8751f
--- /dev/null
+++
b/paimon-api/src/main/java/org/apache/paimon/rest/requests/RegisterTableRequest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.apache.paimon.rest.requests;
+
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.rest.RESTRequest;
+
+import
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
+import
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+/** Request for register table. */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RegisterTableRequest implements RESTRequest {
+
+ private static final String FIELD_IDENTIFIER = "identifier";
+
+ private static final String FIELD_PATH = "path";
+
+ @JsonProperty(FIELD_IDENTIFIER)
+ private final Identifier identifier;
+
+ @JsonProperty(FIELD_PATH)
+ private final String path;
+
+ @JsonCreator
+ public RegisterTableRequest(
+ @JsonProperty(FIELD_IDENTIFIER) Identifier identifier,
+ @JsonProperty(FIELD_PATH) String path) {
+ this.identifier = identifier;
+ this.path = path;
+ }
+
+ @JsonGetter(FIELD_IDENTIFIER)
+ public Identifier getIdentifier() {
+ return identifier;
+ }
+
+ @JsonGetter(FIELD_PATH)
+ public String getPath() {
+ return path;
+ }
+}
diff --git a/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
b/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
index 3de3d50769..3109d7bc2d 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
@@ -561,6 +561,18 @@ public interface Catalog extends AutoCloseable {
throw new UnsupportedOperationException();
}
+ /**
+ * Register a paimon table to the catalog if it does not exist. It is an
asynchronous operation
+ *
+ * @param identifier a table identifier
+ * @param path the path of the table
+ * @throws TableAlreadyExistException if the table already exists in the
catalog.
+ */
+ default void registerTable(Identifier identifier, String path)
+ throws TableAlreadyExistException {
+ throw new UnsupportedOperationException();
+ }
+
/**
* Whether this catalog supports list objects paged. If not, corresponding
methods will fall
* back to listing all objects. For example, {@link
#listTablesPaged(String, Integer, String,
diff --git
a/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java
index 7a1111bde5..08776714a8 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java
@@ -149,6 +149,12 @@ public abstract class DelegateCatalog implements Catalog {
wrapped.alterTable(identifier, changes, ignoreIfNotExists);
}
+ @Override
+ public void registerTable(Identifier identifier, String path)
+ throws TableAlreadyExistException {
+ wrapped.registerTable(identifier, path);
+ }
+
@Override
public boolean supportsListObjectsPaged() {
return wrapped.supportsListObjectsPaged();
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 85dbb29a9c..c7b93a484a 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
@@ -532,6 +532,22 @@ public class RESTCatalog implements Catalog {
}
}
+ @Override
+ public void registerTable(Identifier identifier, String path)
+ throws TableAlreadyExistException {
+ try {
+ api.registerTable(identifier, path);
+ } catch (ForbiddenException e) {
+ throw new TableNoPermissionException(identifier, e);
+ } catch (AlreadyExistsException e) {
+ throw new TableAlreadyExistException(identifier);
+ } catch (ServiceFailureException e) {
+ throw new IllegalStateException(e.getMessage());
+ } catch (BadRequestException e) {
+ throw new RuntimeException(new
IllegalArgumentException(e.getMessage()));
+ }
+ }
+
@Override
public void markDonePartitions(Identifier identifier, List<Map<String,
String>> partitions)
throws TableNotExistException {