mchades commented on code in PR #9551: URL: https://github.com/apache/gravitino/pull/9551#discussion_r2660530675
########## api/src/main/java/org/apache/gravitino/function/FunctionChange.java: ########## @@ -0,0 +1,393 @@ +/* + * 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.function; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.Objects; +import org.apache.gravitino.annotation.Evolving; + +/** Represents a change that can be applied to a function. */ +@Evolving +public interface FunctionChange { + + /** + * Create a {@link FunctionChange} to update the comment of a function. + * + * @param newComment The new comment value. + * @return The change instance. + */ + static FunctionChange updateComment(String newComment) { + return new UpdateComment(newComment); + } + + /** + * Create a {@link FunctionChange} to add a new definition (overload) to a function. + * + * @param definition The new definition to add. + * @return The change instance. + */ + static FunctionChange addDefinition(FunctionDefinition definition) { + return new AddDefinition(definition); + } + + /** + * Create a {@link FunctionChange} to remove an existing definition (overload) from a function. + * + * @param parameters The parameters that identify the definition to remove. + * @return The change instance. + */ + static FunctionChange removeDefinition(FunctionParam[] parameters) { + return new RemoveDefinition(parameters); + } + + /** + * Create a {@link FunctionChange} to add an implementation to a specific definition. + * + * @param parameters The parameters that identify the definition to update. + * @param implementation The implementation to add. + * @return The change instance. + */ + static FunctionChange addImpl(FunctionParam[] parameters, FunctionImpl implementation) { + return new AddImpl(parameters, implementation); + } + + /** + * Create a {@link FunctionChange} to update an implementation for a specific definition and + * runtime. + * + * @param parameters The parameters that identify the definition to update. + * @param runtime The runtime that identifies the implementation to replace. + * @param implementation The new implementation. + * @return The change instance. + */ + static FunctionChange updateImpl( + FunctionParam[] parameters, FunctionImpl.RuntimeType runtime, FunctionImpl implementation) { + return new UpdateImpl(parameters, runtime, implementation); + } + + /** + * Create a {@link FunctionChange} to remove an implementation for a specific definition and + * runtime. + * + * @param parameters The parameters that identify the definition to update. + * @param runtime The runtime that identifies the implementation to remove. + * @return The change instance. + */ + static FunctionChange removeImpl(FunctionParam[] parameters, FunctionImpl.RuntimeType runtime) { + return new RemoveImpl(parameters, runtime); + } + + /** A {@link FunctionChange} to update the comment of a function. */ + final class UpdateComment implements FunctionChange { + private final String newComment; + + UpdateComment(String newComment) { + Preconditions.checkArgument(newComment != null, "New comment cannot be null"); + this.newComment = newComment; + } + + /** + * @return The new comment of the function. + */ + public String newComment() { + return newComment; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof UpdateComment)) { + return false; + } + UpdateComment that = (UpdateComment) obj; + return Objects.equals(newComment, that.newComment); + } + + @Override + public int hashCode() { + return Objects.hash(newComment); + } + + @Override + public String toString() { + return "UpdateComment{newComment='" + newComment + "'}"; + } + } + + /** A {@link FunctionChange} to add a new definition to a function. */ + final class AddDefinition implements FunctionChange { + private final FunctionDefinition definition; + + AddDefinition(FunctionDefinition definition) { + this.definition = Preconditions.checkNotNull(definition, "Definition cannot be null"); + } + + /** + * @return The definition to add. + */ + public FunctionDefinition definition() { + return definition; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof AddDefinition)) { + return false; + } + AddDefinition that = (AddDefinition) obj; + return Objects.equals(definition, that.definition); + } + + @Override + public int hashCode() { + return Objects.hash(definition); + } + + @Override + public String toString() { + return "AddDefinition{definition=" + definition + '}'; + } + } + + /** A {@link FunctionChange} to remove an existing definition from a function. */ + final class RemoveDefinition implements FunctionChange { + private final FunctionParam[] parameters; + + RemoveDefinition(FunctionParam[] parameters) { + Preconditions.checkArgument(parameters != null, "Parameters cannot be null"); + this.parameters = Arrays.copyOf(parameters, parameters.length); + } + + /** + * @return The parameters that identify the definition to remove. + */ + public FunctionParam[] parameters() { + return Arrays.copyOf(parameters, parameters.length); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof RemoveDefinition)) { + return false; + } + RemoveDefinition that = (RemoveDefinition) obj; + return Arrays.equals(parameters, that.parameters); + } + + @Override + public int hashCode() { + return Arrays.hashCode(parameters); + } + + @Override + public String toString() { + return "RemoveDefinition{parameters=" + Arrays.toString(parameters) + '}'; + } + } + + /** A {@link FunctionChange} to add an implementation to a definition. */ + final class AddImpl implements FunctionChange { + private final FunctionParam[] parameters; + private final FunctionImpl implementation; + + AddImpl(FunctionParam[] parameters, FunctionImpl implementation) { + Preconditions.checkArgument(parameters != null, "Parameters cannot be null"); + this.parameters = Arrays.copyOf(parameters, parameters.length); + this.implementation = + Preconditions.checkNotNull(implementation, "Implementation cannot be null"); Review Comment: fixed -- 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]
