jerryshao commented on code in PR #14915:
URL: https://github.com/apache/gravitino/pull/14915#discussion_r4550187237
##########
api/src/main/java/org/apache/gravitino/MetadataObject.java:
##########
@@ -77,7 +77,12 @@ enum Type {
/** A job template represents a reusable template for creating jobs in
Gravitino. */
JOB_TEMPLATE,
/** A function represents a user-defined function registered in Gravitino.
*/
- FUNCTION;
+ FUNCTION,
+ /**
+ * A glossary term defines a business word in a metalake, and can be bound
to the metadata
+ * objects and metrics behind it.
+ */
+ GLOSSARY_TERM;
Review Comment:
GLOSSARY_TERM has no entity mapping yet, but code that loops over every
MetadataObject.Type (for example RelationalGarbageCollector orphan cleanup)
will now hit it and likely throw on every cycle, logging an error each time.
Skip unmapped types in those loops, or add a test that all Type.values() are
handled.
##########
api/src/main/java/org/apache/gravitino/glossary/TermChange.java:
##########
@@ -0,0 +1,806 @@
+/*
+ * 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.glossary;
+
+import com.google.common.base.Preconditions;
+import java.util.Arrays;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.apache.gravitino.annotation.Evolving;
+
+/**
+ * A change to a glossary term, passed to {@link
GlossaryOperations#alterTerm(String,
+ * TermChange...)}. All changes of one call are applied together.
+ *
+ * <p>Adding a synonym, domain, broader term or related term that the term
already has, or removing
+ * one that it does not have, is not an error and changes nothing.
+ */
+@Evolving
+public interface TermChange {
+
+ /**
+ * Creates a change to rename the term. Bindings, relations and domains are
kept.
+ *
+ * @param newName The new name of the term.
+ * @return The term change.
+ */
+ static TermChange rename(String newName) {
+ return new RenameTerm(newName);
+ }
+
+ /**
+ * Creates a change to update the definition of the term.
+ *
+ * @param newDefinition The new definition, or null to remove it.
+ * @return The term change.
+ */
+ static TermChange updateDefinition(@Nullable String newDefinition) {
+ return new UpdateDefinition(newDefinition);
+ }
+
+ /**
+ * Creates a change to set the status of the term. There are no transition
rules: a term can move
+ * from any status to any other.
+ *
+ * @param newStatus The new status.
+ * @return The term change.
+ */
+ static TermChange setStatus(GlossaryTerm.Status newStatus) {
+ return new SetStatus(newStatus);
+ }
+
+ /**
+ * Creates a change to add a synonym to the term. A synonym cannot be the
name of another term or
+ * of this term.
+ *
+ * @param synonym The synonym to add.
+ * @return The term change.
+ */
+ static TermChange addSynonym(String synonym) {
+ return new AddSynonym(synonym);
Review Comment:
TermChange factories (rename, addSynonym, addDomain, setProperty, etc.)
accept null or blank values, while TermSpec.Builder rejects them. Add the same
Preconditions checks here so bad input fails at construction instead of later
in the server.
##########
api/src/main/java/org/apache/gravitino/glossary/TermChange.java:
##########
@@ -0,0 +1,806 @@
+/*
+ * 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.glossary;
+
+import com.google.common.base.Preconditions;
+import java.util.Arrays;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.apache.gravitino.annotation.Evolving;
+
+/**
+ * A change to a glossary term, passed to {@link
GlossaryOperations#alterTerm(String,
+ * TermChange...)}. All changes of one call are applied together.
+ *
+ * <p>Adding a synonym, domain, broader term or related term that the term
already has, or removing
+ * one that it does not have, is not an error and changes nothing.
+ */
+@Evolving
+public interface TermChange {
+
+ /**
+ * Creates a change to rename the term. Bindings, relations and domains are
kept.
+ *
+ * @param newName The new name of the term.
+ * @return The term change.
+ */
+ static TermChange rename(String newName) {
+ return new RenameTerm(newName);
+ }
+
+ /**
+ * Creates a change to update the definition of the term.
+ *
+ * @param newDefinition The new definition, or null to remove it.
+ * @return The term change.
+ */
+ static TermChange updateDefinition(@Nullable String newDefinition) {
+ return new UpdateDefinition(newDefinition);
+ }
+
+ /**
+ * Creates a change to set the status of the term. There are no transition
rules: a term can move
+ * from any status to any other.
+ *
+ * @param newStatus The new status.
+ * @return The term change.
+ */
+ static TermChange setStatus(GlossaryTerm.Status newStatus) {
+ return new SetStatus(newStatus);
+ }
+
+ /**
+ * Creates a change to add a synonym to the term. A synonym cannot be the
name of another term or
+ * of this term.
+ *
+ * @param synonym The synonym to add.
+ * @return The term change.
+ */
+ static TermChange addSynonym(String synonym) {
+ return new AddSynonym(synonym);
+ }
+
+ /**
+ * Creates a change to remove a synonym from the term.
+ *
+ * @param synonym The synonym to remove.
+ * @return The term change.
+ */
+ static TermChange removeSynonym(String synonym) {
+ return new RemoveSynonym(synonym);
+ }
+
+ /**
+ * Creates a change to add the term to a domain.
+ *
+ * @param domain The name of the domain.
+ * @return The term change.
+ */
+ static TermChange addDomain(String domain) {
+ return new AddDomain(domain);
+ }
+
+ /**
+ * Creates a change to remove the term from a domain.
+ *
+ * @param domain The name of the domain.
+ * @return The term change.
+ */
+ static TermChange removeDomain(String domain) {
+ return new RemoveDomain(domain);
+ }
+
+ /**
+ * Creates a change to add a broader term. "A has broader term B" means "A
is a kind of B". The
+ * change fails if it would create a cycle, make a chain of broader terms
longer than the depth
+ * limit, or make a term an ancestor of one of its related terms.
+ *
+ * @param broader The name of the broader term.
+ * @return The term change.
+ */
+ static TermChange addBroader(String broader) {
+ return new AddBroader(broader);
+ }
+
+ /**
+ * Creates a change to remove a broader term.
+ *
+ * @param broader The name of the broader term.
+ * @return The term change.
+ */
+ static TermChange removeBroader(String broader) {
+ return new RemoveBroader(broader);
+ }
+
+ /**
+ * Creates a change to add a related term. The link shows on both terms. The
change fails if one
+ * term is an ancestor of the other.
+ *
+ * @param related The name of the related term.
+ * @return The term change.
+ */
+ static TermChange addRelated(String related) {
+ return new AddRelated(related);
+ }
+
+ /**
+ * Creates a change to remove a related term.
+ *
+ * @param related The name of the related term.
+ * @return The term change.
+ */
+ static TermChange removeRelated(String related) {
+ return new RemoveRelated(related);
+ }
+
+ /**
+ * Creates a change to replace all the documentation links of the term.
+ *
+ * @param links The new links, which replace all current links.
+ * @return The term change.
+ */
+ static TermChange updateLinks(TermLink[] links) {
+ Preconditions.checkArgument(links != null, "Links cannot be null");
+ return new UpdateLinks(links.clone());
+ }
+
+ /**
+ * Creates a change to set the source reference of the term.
+ *
+ * @param sourceRef The source reference, in the form {@code <system>:<id>},
or null to remove it.
+ * @return The term change.
+ */
+ static TermChange setSourceRef(@Nullable String sourceRef) {
+ return new SetSourceRef(sourceRef);
+ }
+
+ /**
+ * Creates a change to set a property of the term.
+ *
+ * @param property The property name.
+ * @param value The property value.
+ * @return The term change.
+ */
+ static TermChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
Review Comment:
setProperty accepts a null key or value, which will surprise
implementations; reject null and blank keys up front.
--
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]