FANNG1 commented on code in PR #5612: URL: https://github.com/apache/gravitino/pull/5612#discussion_r1851913594
########## api/src/main/java/org/apache/gravitino/model/Model.java: ########## @@ -0,0 +1,180 @@ +/* + * 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.gravitino.model; + +import java.util.Collections; +import java.util.Map; +import org.apache.gravitino.Auditable; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.authorization.SupportsRoles; +import org.apache.gravitino.exceptions.ModelVersionAliasesAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchModelException; +import org.apache.gravitino.exceptions.NoSuchModelVersionException; +import org.apache.gravitino.tag.SupportsTags; + +/** + * An interface representing an ML model under a schema {@link Namespace}. A model is a metadata + * object that represents the model artifact in ML. Users can register a model object in Gravitino + * to manage the mode metadata. The typical use case is to manage the model in ML lifecycle with a Review Comment: mode metadata -> model metadata ########## api/src/main/java/org/apache/gravitino/model/Model.java: ########## @@ -0,0 +1,180 @@ +/* + * 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.gravitino.model; + +import java.util.Collections; +import java.util.Map; +import org.apache.gravitino.Auditable; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.authorization.SupportsRoles; +import org.apache.gravitino.exceptions.ModelVersionAliasesAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchModelException; +import org.apache.gravitino.exceptions.NoSuchModelVersionException; +import org.apache.gravitino.tag.SupportsTags; + +/** + * An interface representing an ML model under a schema {@link Namespace}. A model is a metadata + * object that represents the model artifact in ML. Users can register a model object in Gravitino + * to manage the mode metadata. The typical use case is to manage the model in ML lifecycle with a + * unified way in Gravitino, and access the model artifact with a unified identifier. Also, with the + * model registered in Gravitino, users can also govern the model with Gravitino's unified audit, + * tag, and role management. + * + * <p>The difference of Model and tabular data is that the model is schema-free, and the main + * property of the model is the model artifact URL. The difference compared to the fileset is that + * the model is versioned, and the model object contains the version information. + */ +@Evolving +public interface Model extends Auditable { + + /** @return Name of the model object. */ + String name(); + + /** + * The comment of the model object. This is the general description of the model object. User can + * still add more detailed information in the model version. + * + * @return The comment of the model object. Null is returned if no comment is set. + */ + default String comment() { + return null; + } + + /** + * The properties of the model object. The properties are key-value pairs that can be used to + * store additional information of the model object. The properties are optional. + * + * <p>Users can still specify the properties in the model version for different information. + * + * @return the properties of the model object. + */ + default Map<String, String> properties() { + return Collections.emptyMap(); + } + + /** + * The versions of the model object. The model object can have multiple versions. Each version + * contains the detailed information of the model artifact, like the URL, the training properties, + * etc. + * + * @return The versions of the model object. + */ + ModelVersion[] versions(); + + /** + * Get the model version by the version number. If the version does not exist, throw an exception. + * + * @param version The version number of the model. + * @return The model version object. + * @throws NoSuchModelVersionException if the version does not exist. + */ + ModelVersion version(int version) throws NoSuchModelVersionException; + + /** + * Get the model version by the version alias. If the version does not exist, throw an exception. + * + * @param alias The version alias of the model. + * @return The model version object. + * @throws NoSuchModelVersionException if the version does not exist. + */ + ModelVersion versionAlias(String alias) throws NoSuchModelVersionException; + + /** + * Check if the model version exists by the version number. + * + * @param version The version number of the model. + * @return True if the version exists, false otherwise. + */ + default boolean versionExists(int version) { + try { + version(version); + return true; + } catch (NoSuchModelVersionException e) { + return false; + } + } + + /** + * Check if the model version exists by the version alias. + * + * @param alias The version alias of the model. + * @return True if the version exists, false otherwise. + */ + default boolean versionExists(String alias) { + try { + versionAlias(alias); + return true; + } catch (NoSuchModelVersionException e) { + return false; + } + } + + /** + * Link a new version model to the registered model object. The new version model will be added to + * the model object. If the model object does not exist, it will throw an exception. + * + * @param aliases The aliases of the model version. The aliases should be unique in this model, + * otherwise the {@link ModelVersionAliasesAlreadyExistsException} will be thrown. The aliases + * are optional and can be empty. + * @param comment The comment of the model version. The comment is optional and can be null. + * @param uri The model artifact URI. + * @param properties The properties of the model version. The properties are optional and can be + * null or empty. + * @return The created model version object. + * @throws NoSuchModelException If the model does not exist. + * @throws ModelVersionAliasesAlreadyExistsException If the aliases already exist in the model. + */ + ModelVersion link(String[] aliases, String comment, String uri, Map<String, String> properties) Review Comment: place `uri` to the first argument of the method? as it's more important and can't be null ########## api/src/main/java/org/apache/gravitino/model/ModelCatalog.java: ########## @@ -0,0 +1,118 @@ +/* + * 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.gravitino.model; + +import java.util.Map; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.ModelAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchModelException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** + * The ModelCatalog interface defines the public API for managing model objects in a schema. If the + * catalog implementation supports model objects, it should implement this interface. + */ +@Evolving +public interface ModelCatalog { + + /** + * List the models in a schema namespace from the catalog. + * + * @param namespace A schema namespace. + * @return An array of model identifiers in the namespace. + * @throws NoSuchSchemaException If the schema does not exist. + */ + NameIdentifier[] listModels(Namespace namespace) throws NoSuchSchemaException; + + /** + * Get a model metadata by {@link NameIdentifier} from the catalog. + * + * @param ident A model identifier. + * @return The model metadata. + * @throws NoSuchModelException If the model does not exist. + */ + Model getModel(NameIdentifier ident) throws NoSuchModelException; + + /** + * Check if a model exists using an {@link NameIdentifier} from the catalog. + * + * @param ident A model identifier. + * @return true If the model exists, false if the model does not exist. + */ + default boolean modelExists(NameIdentifier ident) { + try { + getModel(ident); + return true; + } catch (NoSuchModelException e) { + return false; + } + } + + /** + * Register a model in the catalog if the model is not existed, otherwise the {@link + * ModelAlreadyExistsException} will be thrown. The {@link Model} object will be created the model + * is registered, users can call {@link Model#link(String[], String, String, Map)} to link the + * model version to the registered {@link Model}. + * + * @param ident The name identifier of the model. + * @param comment The comment of the model. The comment is optional and can be null. + * @param properties The properties of the model. The properties are optional and can be null or + * empty. + * @return The registered model object. + * @throws ModelAlreadyExistsException If the model already registered. + */ + default Model registerModel(NameIdentifier ident, String comment, Map<String, String> properties) + throws ModelAlreadyExistsException { + return registerModel(ident, new String[0], comment, null, properties); + } + + /** + * Register a model in the catalog if the model is not existed, otherwise the {@link + * ModelAlreadyExistsException} will be thrown. The {@link Model} object will be created when the + * model is registered, in the meantime, the model version (version 0) will also be created and + * linked to the registered model. + * + * @param ident The name identifier of the model. + * @param aliases The aliases of the model version. The alias are optional and can be empty. + * @param comment The comment of the model. The comment is optional and can be null. + * @param url The model artifact URL. + * @param properties The properties of the model. The properties are optional and can be null or + * empty. + * @return The registered model object. + * @throws ModelAlreadyExistsException If the model already registered. + */ + Model registerModel( Review Comment: At first glance, it's confusing to add `aliases` and `url` when registerModel. After read the document, this method contains there actions: 1. register a model, 2, create a model version, 3, link model version to the model. is it necessary to provide this method? ########## api/src/main/java/org/apache/gravitino/model/ModelCatalog.java: ########## @@ -0,0 +1,118 @@ +/* + * 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.gravitino.model; + +import java.util.Map; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.ModelAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchModelException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** + * The ModelCatalog interface defines the public API for managing model objects in a schema. If the + * catalog implementation supports model objects, it should implement this interface. + */ +@Evolving +public interface ModelCatalog { + + /** + * List the models in a schema namespace from the catalog. + * + * @param namespace A schema namespace. + * @return An array of model identifiers in the namespace. + * @throws NoSuchSchemaException If the schema does not exist. + */ + NameIdentifier[] listModels(Namespace namespace) throws NoSuchSchemaException; + + /** + * Get a model metadata by {@link NameIdentifier} from the catalog. + * + * @param ident A model identifier. + * @return The model metadata. + * @throws NoSuchModelException If the model does not exist. + */ + Model getModel(NameIdentifier ident) throws NoSuchModelException; + + /** + * Check if a model exists using an {@link NameIdentifier} from the catalog. + * + * @param ident A model identifier. + * @return true If the model exists, false if the model does not exist. + */ + default boolean modelExists(NameIdentifier ident) { + try { + getModel(ident); + return true; + } catch (NoSuchModelException e) { + return false; + } + } + + /** + * Register a model in the catalog if the model is not existed, otherwise the {@link + * ModelAlreadyExistsException} will be thrown. The {@link Model} object will be created the model Review Comment: `The {@link Model} object will be created the model` -> `The {@link Model} object will be created after the model ` -- 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]
