jerryshao commented on code in PR #6861:
URL: https://github.com/apache/gravitino/pull/6861#discussion_r2041944082
##########
core/src/main/java/org/apache/gravitino/catalog/ModelOperationDispatcher.java:
##########
@@ -236,6 +239,53 @@ public Model alterModel(NameIdentifier ident,
ModelChange... changes)
alteredModel.properties()));
}
+ /** {@inheritDoc} */
+ @Override
+ public ModelVersion alterModelVersion(
+ NameIdentifier ident, int version, ModelVersionChange... changes)
+ throws NoSuchModelVersionException, IllegalArgumentException {
+ validateAlterProperties(ident,
HasPropertyMetadata::modelPropertiesMetadata, changes);
+ return executeAlterModelVersion(ident, f -> f.alterModelVersion(ident,
version, changes));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ModelVersion alterModelVersion(
+ NameIdentifier ident, String alias, ModelVersionChange... changes)
+ throws NoSuchModelException, IllegalArgumentException {
+ validateAlterProperties(ident,
HasPropertyMetadata::modelPropertiesMetadata, changes);
+ return executeAlterModelVersion(ident, f -> f.alterModelVersion(ident,
alias, changes));
+ }
+
+ private ModelVersion executeAlterModelVersion(
+ NameIdentifier ident, ThrowableFunction<ModelCatalog, ModelVersion> fn) {
+
Review Comment:
Remove this empty line.
##########
core/src/main/java/org/apache/gravitino/catalog/ModelOperationDispatcher.java:
##########
@@ -236,6 +239,53 @@ public Model alterModel(NameIdentifier ident,
ModelChange... changes)
alteredModel.properties()));
}
+ /** {@inheritDoc} */
+ @Override
+ public ModelVersion alterModelVersion(
+ NameIdentifier ident, int version, ModelVersionChange... changes)
+ throws NoSuchModelVersionException, IllegalArgumentException {
+ validateAlterProperties(ident,
HasPropertyMetadata::modelPropertiesMetadata, changes);
+ return executeAlterModelVersion(ident, f -> f.alterModelVersion(ident,
version, changes));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ModelVersion alterModelVersion(
+ NameIdentifier ident, String alias, ModelVersionChange... changes)
+ throws NoSuchModelException, IllegalArgumentException {
+ validateAlterProperties(ident,
HasPropertyMetadata::modelPropertiesMetadata, changes);
+ return executeAlterModelVersion(ident, f -> f.alterModelVersion(ident,
alias, changes));
+ }
+
+ private ModelVersion executeAlterModelVersion(
+ NameIdentifier ident, ThrowableFunction<ModelCatalog, ModelVersion> fn) {
+
+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);
+
+ ModelVersion alteredModelVersion =
+ TreeLockUtils.doWithTreeLock(
+ ident,
+ LockType.WRITE,
+ () ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithModelOps(fn),
+ NoSuchModelVersionException.class,
+ IllegalArgumentException.class));
+
+ return internalUpdateModelVersion(catalogIdent, alteredModelVersion);
+ }
+
+ private ModelVersion internalUpdateModelVersion(
Review Comment:
I don't see the value of having this method, there's only one place that
uses this, I think we don't need this method. Besides, the method name is a bit
weird, the name doesn't reflect the implementation.
##########
core/src/main/java/org/apache/gravitino/listener/api/event/AlterModelVersionFailureEvent.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.listener.api.event;
+
+import java.util.Optional;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.model.ModelVersionChange;
+
+/** Represents an event triggered when a model version alteration operation
fails. */
+@DeveloperApi
+public class AlterModelVersionFailureEvent extends ModelFailureEvent {
+ private final Optional<String> alias;
+ private final Optional<Integer> version;
+ private ModelVersionChange[] modelVersionChanges;
+
+ /**
+ * Constructs a new {@code AlterModelVersionFailureEvent} instance. Only one
of {@code alias} or
+ * {@code version} should be specified.
+ *
+ * @param user the user who triggered the event
+ * @param identifier the identifier of the model involved in the event
+ * @param exception the exception that caused the failure
+ * @param alias the alias of the model version involved in the event, or
{@code null} if not
+ * specified
+ * @param version the version of the model version involved in the event, or
{@code null} if not
+ * specified
+ * @param modelVersionChanges an array of {@code ModelVersionChange}
instances that were attempted
+ * to be applied
+ */
+ public AlterModelVersionFailureEvent(
+ String user,
+ NameIdentifier identifier,
+ Exception exception,
+ String alias,
+ Integer version,
Review Comment:
You can implement a `Either` class to store `alias` or `version`, you can
refer to here
(https://stackoverflow.com/questions/26162407/is-there-an-equivalent-of-scalas-either-in-java-8).
##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java:
##########
@@ -1376,14 +1376,22 @@ public static ModelVersionEntity fromModelVersionPO(
}
}
+ /**
+ * Updata ModelPO with new ModelEntity object, metalakeID, catalogID,
schemaID will be the same as
+ * the old one. the id, name, comment, properties, latestVersion and
auditInfo will be updated.
+ *
+ * @param oldModelPO the old ModelPO object
+ * @param newModel the new ModelEntity object
+ * @return the updated ModelPO object
+ */
public static ModelPO updateModelPO(ModelPO oldModelPO, ModelEntity
newModel) {
try {
return ModelPO.builder()
- .withModelId(newModel.id())
- .withModelName(newModel.name())
.withMetalakeId(oldModelPO.getMetalakeId())
.withCatalogId(oldModelPO.getCatalogId())
.withSchemaId(oldModelPO.getSchemaId())
+ .withModelId(newModel.id())
+ .withModelName(newModel.name())
Review Comment:
What is the purpose of this change here?
--
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]