lihaosky commented on code in PR #25036:
URL: https://github.com/apache/flink/pull/25036#discussion_r1692573488


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/Catalog.java:
##########
@@ -790,4 +792,126 @@ void alterPartitionColumnStatistics(
             CatalogColumnStatistics columnStatistics,
             boolean ignoreIfNotExists)
             throws PartitionNotExistException, CatalogException;
+
+    // ------ models  ------
+
+    /**
+     * Get names of all tables models under this database. An empty list is 
returned if none exists.
+     *
+     * @return a list of the names of all models in this database
+     * @throws DatabaseNotExistException if the database does not exist
+     * @throws CatalogException in case of any runtime exception
+     */
+    default List<String> listModels(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException(
+                String.format("listModel(String) is not implemented for %s.", 
this.getClass()));
+    }
+
+    /**
+     * Returns a {@link CatalogModel} identified by the given {@link 
ObjectPath}.
+     *
+     * @param modelPath Path of the model
+     * @return The requested model
+     * @throws ModelNotExistException if the target does not exist
+     * @throws CatalogException in case of any runtime exception
+     */
+    default CatalogModel getModel(ObjectPath modelPath)
+            throws ModelNotExistException, CatalogException {
+        throw new UnsupportedOperationException(
+                String.format("getModel(ObjectPath) is not implemented for 
%s.", this.getClass()));
+    }
+
+    /**
+     * Check if a model exists in this catalog.
+     *
+     * @param modelPath Path of the model
+     * @return true if the given model exists in the catalog false otherwise
+     * @throws CatalogException in case of any runtime exception
+     */
+    default boolean modelExists(ObjectPath modelPath) throws CatalogException {
+        throw new UnsupportedOperationException(
+                String.format(
+                        "modelExists(ObjectPath) is not implemented for %s.", 
this.getClass()));
+    }
+
+    /**
+     * Drop a model.
+     *
+     * @param modelPath Path of the model to be dropped
+     * @param ignoreIfNotExists Flag to specify behavior when the model does 
not exist: if set to
+     *     false, throw an exception, if set to true, do nothing.
+     * @throws ModelNotExistException if the model does not exist
+     * @throws CatalogException in case of any runtime exception
+     */
+    default void dropModel(ObjectPath modelPath, boolean ignoreIfNotExists)
+            throws ModelNotExistException, CatalogException {
+        throw new UnsupportedOperationException(
+                String.format(
+                        "dropModel(ObjectPath, boolean) is not implemented for 
%s.",
+                        this.getClass()));
+    }
+
+    /**
+     * Rename an existing model.
+     *
+     * @param modelPath Path of the model to be renamed
+     * @param newModelName the new name of the model
+     * @param ignoreIfNotExists Flag to specify behavior when the model does 
not exist: if set to
+     *     false, throw an exception, if set to true, do nothing.
+     * @throws ModelNotExistException if the model does not exist
+     * @throws CatalogException in case of any runtime exception
+     */
+    default void renameModel(ObjectPath modelPath, String newModelName, 
boolean ignoreIfNotExists)
+            throws ModelNotExistException, ModelAlreadyExistException, 
CatalogException {
+        throw new UnsupportedOperationException(
+                String.format(
+                        "renameModel(ObjectPath, String, boolean) is not 
implemented for %s.",
+                        this.getClass()));
+    }
+
+    /**
+     * Creates a new model.
+     *
+     * @param modelPath path of the model to be created
+     * @param model the CatalogModel definition
+     * @param ignoreIfExists flag to specify behavior when a model already 
exists at the given path:
+     *     if set to false, it throws a ModelAlreadyExistException, if set to 
true, do nothing.
+     * @throws ModelAlreadyExistException if model already exists and 
ignoreIfExists is false
+     * @throws DatabaseNotExistException if the database in tablePath doesn't 
exist
+     * @throws CatalogException in case of any runtime exception
+     */
+    default void createModel(ObjectPath modelPath, CatalogModel model, boolean 
ignoreIfExists)
+            throws ModelAlreadyExistException, DatabaseNotExistException, 
CatalogException {
+        throw new UnsupportedOperationException(
+                String.format(
+                        "createModel(ObjectPath, CatalogModel, boolean) is not 
implemented for %s.",
+                        this.getClass()));
+    }
+
+    /**
+     * Modifies an existing model. Note that the new and old {@link 
CatalogModel} must be of the
+     * same kind. For example, this doesn't allow altering a remote model to 
import model or native
+     * model, and vice versa. Note that the newModel contains only changes. 
Current alter model
+     * syntax supports alter properties and rename. This call is for altering 
model properties.
+     * Therefore, the newModel's properties are only changed properties. It's 
up to catalog
+     * implementation to apply the changes. The reason for this behavior is 
that this doesn't
+     * dictate how catalog implementation should handle model alteration. For 
example, it can do
+     * Read-modify-write or merge in place etc.
+     *
+     * @param modelPath path of the model to be modified
+     * @param modelChange the CatalogModel containing only changes

Review Comment:
   The original thought is that I don't want to check model existence like 
table in 
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java#L420-L423
 and return `NopOperation` if model doesn't exist. I want to let catalog check 
it and apply the change. But I guess I can introduce `ModelChange` like 
`TableChange` in `SqlModelAlterOperation` in next PR and make the model there 
optional if doesn't exist.



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