JingsongLi commented on code in PR #10881:
URL: https://github.com/apache/paimon/pull/10881#discussion_r4479078780


##########
paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java:
##########
@@ -1760,6 +1763,44 @@ public void dropFunction(Identifier identifier) {
                 restAuthFunction);
     }
 
+    /** List model metadata for a database. */
+    public List<GetModelResponse> listModels(String databaseName) {
+        return listDataFromPageApi(

Review Comment:
   [P2] Follow the model list cursor across an empty page. With 
`{"models":[],"nextPageToken":"second"}` followed by a page containing one 
model, Java returns an empty list after the first request while Python follows 
the cursor and returns the model. This loses results if the backend filters a 
page before returning it. Please honor the cursor on empty pages, or define and 
enforce the same nonempty nonterminal-page contract in the server and both 
clients.



##########
paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java:
##########
@@ -1116,6 +1119,73 @@ public boolean supportsPartitionModification() {
         return false;
     }
 
+    @Override
+    public List<Model> listModels(String databaseName) throws 
DatabaseNotExistException {
+        try {
+            return api.listModels(databaseName).stream()
+                    .map(response -> response.toModel(databaseName))
+                    .collect(Collectors.toList());
+        } catch (NoSuchResourceException e) {
+            throw new DatabaseNotExistException(databaseName, e);
+        } catch (NotImplementedException e) {
+            throw new UnsupportedOperationException("REST Catalog does not 
support models", e);
+        }
+    }
+
+    @Override
+    public Model getModel(Identifier identifier)
+            throws ModelNotExistException, DatabaseNotExistException {
+        try {
+            return 
api.getModel(identifier).toModel(identifier.getDatabaseName());
+        } catch (NoSuchResourceException e) {
+            if (StringUtils.equals(e.resourceType(), 
ErrorResponse.RESOURCE_TYPE_DATABASE)) {
+                throw new 
DatabaseNotExistException(identifier.getDatabaseName(), e);
+            }
+            throw new ModelNotExistException(identifier, e);
+        } catch (NotImplementedException e) {
+            throw new UnsupportedOperationException("REST Catalog does not 
support models", e);
+        }
+    }
+
+    @Override
+    public Model createModel(Identifier identifier, Model model, boolean 
ignoreIfExists)
+            throws ModelAlreadyExistException, DatabaseNotExistException, 
ModelNotExistException {
+        checkArgument(
+                identifier.getFullName().equals(model.fullName()),
+                "Model identifier must match the model metadata");
+        try {
+            return api.createModel(identifier, new CreateModelRequest(model))
+                    .toModel(identifier.getDatabaseName());
+        } catch (AlreadyExistsException e) {
+            if (ignoreIfExists) {
+                return getModel(identifier);
+            }
+            throw new ModelAlreadyExistException(identifier, e);
+        } catch (NoSuchResourceException e) {
+            throw new DatabaseNotExistException(identifier.getDatabaseName(), 
e);
+        } catch (NotImplementedException e) {
+            throw new UnsupportedOperationException("REST Catalog does not 
support models", e);
+        }
+    }
+
+    @Override
+    public void dropModel(Identifier identifier, boolean ignoreIfNotExists)
+            throws ModelNotExistException, DatabaseNotExistException {
+        try {
+            api.dropModel(identifier);
+        } catch (NoSuchResourceException e) {
+            if (StringUtils.equals(e.resourceType(), 
ErrorResponse.RESOURCE_TYPE_DATABASE)) {
+                throw new 
DatabaseNotExistException(identifier.getDatabaseName(), e);
+            }
+            if (ignoreIfNotExists) {

Review Comment:
   [P2] Ignore only a 404 explicitly identifying a missing `MODEL`. Both SDKs 
currently suppress an untyped route 404 when the ignore flag is set. A loopback 
server returning plain `404 Not Found` reproduced this in Python. During 
rollout an older server or gateway without the route can report a successful 
drop to the caller. Preserve the typed `DATABASE` exception, suppress only 
typed `MODEL`, and surface other 404s. Please cover this in both SDKs.



##########
paimon-api/src/main/java/org/apache/paimon/rest/ResourcePaths.java:
##########
@@ -149,6 +150,16 @@ public String database(String databaseName) {
         return SLASH.join(V1, prefix, DATABASES, encodeString(databaseName));
     }
 
+    public String models(String databaseName) {
+        return SLASH.join(V1, prefix, DATABASES, encodeString(databaseName), 
MODELS);
+    }
+
+    public String model(String databaseName, String modelName) {
+        checkArgument(
+                modelName != null && !modelName.trim().isEmpty(), "modelName 
must not be blank");
+        return SLASH.join(models(databaseName), encodeString(modelName));

Review Comment:
   [P1] Reject dot segments before issuing a model request. A loopback HTTP 
server received `DELETE /v1/catalog/databases/my_database/models/..` from Java 
`dropModel(Identifier.create("my_database", ".."))`. A proxy or router that 
resolves dot segments and accepts a trailing slash can route this to the 
database DELETE endpoint. A principal with database-drop permission could 
delete the database while attempting to drop a model. Apply the same name 
validation to create, get, list, and drop in both SDKs and document it in 
OpenAPI. Python item methods already reject dot segments, but 
`list_models("..")` still sends `GET /v1/catalog/models`.



##########
paimon-python/pypaimon/api/rest_api.py:
##########
@@ -740,6 +742,46 @@ def alter_function(self, identifier: Identifier, changes: 
List) -> None:
             self.rest_auth_function,
         )
 
+    def list_models(self, database_name: str) -> List[GetModelResponse]:
+        if not database_name or not database_name.strip():
+            raise ValueError("Database name cannot be empty")
+        return self.__list_data_from_page_api(
+            lambda query_params: self.client.get_with_params(
+                self.resource_paths.models(database_name),
+                query_params,
+                ListModelsResponse,
+                self.rest_auth_function,
+            )
+        )
+
+    def get_model(self, identifier: Identifier) -> GetModelResponse:
+        database_name, model_name = self._validate_resource_path(identifier)
+        return self.client.get(
+            self.resource_paths.model(database_name, model_name),
+            GetModelResponse,
+            self.rest_auth_function,
+        )
+
+    def create_model(
+            self, identifier: Identifier, request: CreateModelRequest
+    ) -> GetModelResponse:
+        database_name, model_name = self._validate_resource_path(identifier)
+        if request.name != model_name:
+            raise ValueError("Model request name must match the identifier")
+        return self.client.post_with_response_type(

Review Comment:
   [P1] Send model creation requests as JSON with bearer auth. The new call 
sends serialized bytes through `data=` without setting `Content-Type`. A 
loopback server enforcing the new OpenAPI `application/json` request body 
returned HTTP 415. Please set the header for this JSON request regardless of 
auth provider and assert it in the existing HTTP test.



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