Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#3460] feat(api): Add API design for Tag system (#3486)

Jerry Shao29a3d62ee2a8
diff --git a/api/src/main/java/com/datastrato/gravitino/MetadataObject.java b/api/src/main/java/com/datastrato/gravitino/MetadataObject.java
new file mode 100644
index 0000000000..a166d7768b
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/MetadataObject.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino;
+
+import com.datastrato.gravitino.annotation.Unstable;
+import javax.annotation.Nullable;
+
+/**
+ * The MetadataObject is the basic unit of the Gravitino system. It represents the metadata object
+ * in the Gravitino system. The object can be a metalake, catalog, schema, table, topic, etc.
+ */
+@Unstable
+public interface MetadataObject {
+ /**
+ * The type of object in the Gravitino system. Every type will map one kind of the entity of the
+ * underlying system.
+ */
+ enum Type {
+ /**
+ * A metalake is a concept of tenant. It means an organization. A metalake contains many data
+ * sources.
+ */
+ METALAKE,
+ /**
+ * A catalog is a collection of metadata from a specific metadata source, like Apache Hive
+ * catalog, Apache Iceberg catalog, JDBC catalog, etc.
+ */
+ CATALOG,
+ /**
+ * A schema is a sub collection of the catalog. The schema can contain filesets, tables, topics,
+ * etc.
+ */
+ SCHEMA,
+ /** A fileset is mapped to a directory on a file system like HDFS, S3, ADLS, GCS, etc. */
+ FILESET,
+ /** A table is mapped the table of relational data sources like Apache Hive, MySQL, etc. */
+ TABLE,
+ /**
+ * A topic is mapped the topic of messaging data sources like Apache Kafka, Apache Pulsar, etc.
+ */
+ TOPIC,
+ /** A column is a sub-collection of the table that represents a group of same type data. */
+ COLUMN
+ }
+
+ /**
+ * The parent full name of the object. If the object doesn't have parent, this method will return
+ * null.
+ *
+ * @return The parent full name of the object.
+ */
+ @Nullable
+ String parent();
+
+ /**
+ * The name of th object.
+ *
+ * @return The name of the object.
+ */
+ String name();
+
+ /**
+ * The full name of th object. Full name will be separated by "." to represent a string identifier
+ * of the object, like catalog, catalog.table, etc.
+ *
+ * @return The name of the object.
+ */
+ String fullName();
+
+ /**
+ * The type of the object.
+ *
+ * @return The type of the object.
+ */
+ Type type();
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
index 8cc27bb719..195e5e994c 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
@@ -4,9 +4,9 @@
*/
package com.datastrato.gravitino.authorization;
+import com.datastrato.gravitino.MetadataObject;
import com.datastrato.gravitino.annotation.Unstable;
import java.util.List;
-import javax.annotation.Nullable;
/**
* The securable object is the entity which access can be granted. Unless allowed by a grant, access
@@ -41,38 +41,7 @@ import javax.annotation.Nullable;
* can use add `read table` privilege for `catalog1.schema1` directly
*/
@Unstable
-public interface SecurableObject {
-
- /**
- * The parent full name of securable object. If the securable object doesn't have parent, this
- * method will return null.
- *
- * @return The parent full name of securable object.
- */
- @Nullable
- String parent();
-
- /**
- * The name of th securable object.
- *
- * @return The name of the securable object.
- */
- String name();
-
- /**
- * The full name of th securable object. If the parent isn't null, the full name will join the
- * parent full name and the name with `.`, otherwise will return the name.
- *
- * @return The name of the securable object.
- */
- String fullName();
-
- /**
- * The type of securable object
- *
- * @return The type of securable object.
- */
- Type type();
+public interface SecurableObject extends MetadataObject {
/**
* The privileges of the securable object. For example: If the securable object is a table, the
@@ -82,34 +51,4 @@ public interface SecurableObject {
* @return The privileges of the role.
*/
List<Privilege> privileges();
-
- /**
- * The type of securable object in the Gravitino system. Every type will map one kind of the
- * entity of the underlying system.
- */
- enum Type {
- /**
- * A catalog is a collection of metadata from a specific metadata source, like Apache Hive
- * catalog, Apache Iceberg catalog, JDBC catalog, etc.
- */
- CATALOG,
- /**
- * A schema is a sub collection of the catalog. The schema can contain filesets, tables, topics,
- * etc.
- */
- SCHEMA,
- /** A fileset is mapped to a directory on a file system like HDFS, S3, ADLS, GCS, etc. */
- FILESET,
- /** A table is mapped the table of relational data sources like Apache Hive, MySQL, etc. */
- TABLE,
- /**
- * A topic is mapped the topic of messaging data sources like Apache Kafka, Apache Pulsar, etc.
- */
- TOPIC,
- /**
- * A metalake is a concept of tenant. It means an organization. A metalake contains many data
- * sources.
- */
- METALAKE
- }
}
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
index 46022c6a83..7cf4fa8c76 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
@@ -4,11 +4,13 @@
*/
package com.datastrato.gravitino.authorization;
+import com.datastrato.gravitino.MetadataObject;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
/** The helper class for {@link SecurableObject}. */
@@ -139,7 +141,11 @@ public class SecurableObjects {
@Override
public String fullName() {
- return toString();
+ if (parent != null) {
+ return parent + "." + name;
+ } else {
+ return name;
+ }
}
@Override
@@ -159,11 +165,18 @@ public class SecurableObjects {
@Override
public String toString() {
- if (parent != null) {
- return parent + "." + name;
- } else {
- return name;
- }
+ String privilegesStr =
+ privileges.stream()
+ .map(p -> "[" + p.simpleString() + "]")
+ .collect(Collectors.joining(","));
+
+ return "SecurableObject: [fullName="
+ + fullName()
+ + "], [type="
+ + type
+ + "], [privileges="
+ + privilegesStr
+ + "]";
}
@Override
@@ -189,9 +202,9 @@ public class SecurableObjects {
* @return The created {@link SecurableObject}
*/
public static SecurableObject parse(
- String fullName, SecurableObject.Type type, List<Privilege> privileges) {
+ String fullName, MetadataObject.Type type, List<Privilege> privileges) {
if ("*".equals(fullName)) {
- if (type != SecurableObject.Type.METALAKE) {
+ if (type != MetadataObject.Type.METALAKE) {
throw new IllegalArgumentException("If securable object isn't metalake, it can't be `*`");
}
return SecurableObjects.ofAllMetalakes(privileges);
@@ -215,7 +228,7 @@ public class SecurableObjects {
* @return The created {@link SecurableObject}
*/
static SecurableObject of(
- SecurableObject.Type type, List<String> names, List<Privilege> privileges) {
+ MetadataObject.Type type, List<String> names, List<Privilege> privileges) {
if (names == null) {
throw new IllegalArgumentException("Cannot create a securable object with null names");
}
@@ -234,8 +247,8 @@ public class SecurableObjects {
}
if (names.size() == 1
- && type != SecurableObject.Type.CATALOG
- && type != SecurableObject.Type.METALAKE) {
+ && type != MetadataObject.Type.CATALOG
+ && type != MetadataObject.Type.METALAKE) {
throw new IllegalArgumentException(
"If the length of names is 1, it must be the CATALOG or METALAKE type");
}
@@ -245,9 +258,9 @@ public class SecurableObjects {
}
if (names.size() == 3
- && type != SecurableObject.Type.FILESET
- && type != SecurableObject.Type.TABLE
- && type != SecurableObject.Type.TOPIC) {
+ && type != MetadataObject.Type.FILESET
+ && type != MetadataObject.Type.TABLE
+ && type != MetadataObject.Type.TOPIC) {
throw new IllegalArgumentException(
"If the length of names is 3, it must be FILESET, TABLE or TOPIC");
}
diff --git a/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchTagException.java b/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchTagException.java
new file mode 100644
index 0000000000..2cdae1a019
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchTagException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+
+/** Exception thrown when a tag with specified name is not existed. */
+public class NoSuchTagException extends NotFoundException {
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchTagException(String message, Object... args) {
+ super(message, args);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param cause the cause.
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchTagException(Throwable cause, String message, Object... args) {
+ super(cause, message, args);
+ }
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/exceptions/TagAlreadyExistsException.java b/api/src/main/java/com/datastrato/gravitino/exceptions/TagAlreadyExistsException.java
new file mode 100644
index 0000000000..385852a754
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/exceptions/TagAlreadyExistsException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+
+/** Exception thrown when a tag with specified name already exists. */
+public class TagAlreadyExistsException extends AlreadyExistsException {
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public TagAlreadyExistsException(String message, Object... args) {
+ super(message, args);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param cause the cause.
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public TagAlreadyExistsException(Throwable cause, String message, Object... args) {
+ super(cause, message, args);
+ }
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/tag/SupportsTags.java b/api/src/main/java/com/datastrato/gravitino/tag/SupportsTags.java
new file mode 100644
index 0000000000..3259029fae
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/tag/SupportsTags.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.tag;
+
+import com.datastrato.gravitino.annotation.Evolving;
+import com.datastrato.gravitino.exceptions.NoSuchTagException;
+
+/**
+ * Interface for supporting getting or associate tags to objects. This interface will be mixed with
+ * metadata objects to provide tag operations.
+ */
+@Evolving
+public interface SupportsTags {
+
+ /**
+ * List all the tag names for the specific object.
+ *
+ * @return The list of tag names.
+ */
+ String[] listTags();
+
+ /**
+ * List all the tags with details for the specific object.
+ *
+ * @return The list of tags.
+ */
+ Tag[] listTagsInfo();
+
+ /**
+ * Get a tag by its name for the specific object.
+ *
+ * @param name The name of the tag.
+ * @return The tag.
+ */
+ Tag getTag(String name) throws NoSuchTagException;
+
+ /**
+ * Associate tags to the specific object. The tagsToAdd will be added to the object, and the
+ * tagsToRemove will be removed from the object.
+ *
+ * @param tagsToAdd The arrays of tag name to be added to the object.
+ * @param tagsToRemove The array of tag name to be removed from the object.
+ * @return The array of tag names that are associated with the object.
+ */
+ String[] associateTags(String[] tagsToAdd, String[] tagsToRemove);
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/tag/Tag.java b/api/src/main/java/com/datastrato/gravitino/tag/Tag.java
new file mode 100644
index 0000000000..c1bb51d286
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/tag/Tag.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.tag;
+
+import com.datastrato.gravitino.Auditable;
+import com.datastrato.gravitino.MetadataObject;
+import com.datastrato.gravitino.annotation.Evolving;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * The interface of a tag. A tag is a label that can be attached to a catalog, schema, table,
+ * fileset, topic, or column. It can be used to categorize, classify, or annotate these objects.
+ */
+@Evolving
+public interface Tag extends Auditable {
+
+ /**
+ * A reserved property to specify the color of the tag. The color is a string of hex code that
+ * represents the color of the tag. The color is used to visually distinguish the tag from other
+ * tags.
+ */
+ String PROPERTY_COLOR = "color";
+
+ /** @return The name of the tag. */
+ String name();
+
+ /** @return The comment of the tag. */
+ String comment();
+
+ /** @return The properties of the tag. */
+ Map<String, String> properties();
+
+ /**
+ * Check if the tag is inherited from a parent object or not. If the tag is inherited, it will
+ * return true, if it is owned by the object itself, it will return false.
+ *
+ * <p>Note. The return value is optional, only when the tag is associated with an object, and
+ * called from the object, the return value will be present. Otherwise, it will be empty.
+ *
+ * @return True if the tag is inherited, false if it is owned by the object itself. Empty if the
+ * tag is not associated with any object.
+ */
+ Optional<Boolean> inherited();
+
+ /** @return The associated objects of the tag. */
+ default AssociatedObjects associatedObjects() {
+ throw new UnsupportedOperationException("The associatedObjects method is not supported.");
+ }
+
+ /** The interface of the associated objects of the tag. */
+ interface AssociatedObjects {
+
+ /** @return The number of objects that are associated with this Tag */
+ default int count() {
+ MetadataObject[] objects = objects();
+ return objects == null ? 0 : objects.length;
+ }
+
+ /** @return The list of objects that are associated with this tag. */
+ MetadataObject[] objects();
+ }
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/tag/TagChange.java b/api/src/main/java/com/datastrato/gravitino/tag/TagChange.java
new file mode 100644
index 0000000000..1f5c30fca5
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/tag/TagChange.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.tag;
+
+import com.datastrato.gravitino.annotation.Evolving;
+
+/**
+ * Interface for supporting tag changes. This interface will be used to provide tag modification
+ * operations for each tag.
+ */
+@Evolving
+public interface TagChange {
+
+ /**
+ * Creates a new tag change to rename the tag.
+ *
+ * @param newName The new name of the tag.
+ * @return The tag change.
+ */
+ static TagChange rename(String newName) {
+ return new RenameTag(newName);
+ }
+
+ /**
+ * Creates a new tag change to update the tag comment.
+ *
+ * @param newComment The new comment for the tag.
+ * @return The tag change.
+ */
+ static TagChange updateComment(String newComment) {
+ return new UpdateTagComment(newComment);
+ }
+
+ /**
+ * Creates a new tag change to set the property and value for the tag.
+ *
+ * @param property The property name to set.
+ * @param value The value to set the property to.
+ * @return The tag change.
+ */
+ static TagChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
+ }
+
+ /**
+ * Creates a new tag change to remove a property from the tag.
+ *
+ * @param property The property name to remove.
+ * @return The tag change.
+ */
+ static TagChange removeProperty(String property) {
+ return new RemoveProperty(property);
+ }
+
+ /** A tag change to rename the tag. */
+ final class RenameTag implements TagChange {
+ private final String newName;
+
+ private RenameTag(String newName) {
+ this.newName = newName;
+ }
+
+ /**
+ * Get the new name of the tag.
+ *
+ * @return The new name of the tag.
+ */
+ public String getNewName() {
+ return newName;
+ }
+
+ /**
+ * Compare the RenameTag instance with another object for equality. Two instances are considered
+ * equal if the new name is the same.
+ *
+ * @param o The object to compare with this instance.
+ * @return True if the object is equal to this instance, false otherwise.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ RenameTag renameTag = (RenameTag) o;
+ return newName.equals(renameTag.newName);
+ }
+
+ /**
+ * Generates a hash code for the RenameTag instance.
+ *
+ * @return The hash code for the RenameTag instance.
+ */
+ @Override
+ public int hashCode() {
+ return newName.hashCode();
+ }
+
+ /**
+ * Get the string representation of the RenameTag instance.
+ *
+ * @return The string representation of the RenameTag instance.
+ */
+ @Override
+ public String toString() {
+ return "RENAMETAG " + newName;
+ }
+ }
+
+ /** A tag change to update the tag comment. */
+ final class UpdateTagComment implements TagChange {
+ private final String newComment;
+
+ private UpdateTagComment(String newComment) {
+ this.newComment = newComment;
+ }
+
+ /**
+ * Get the new comment intended for the tag.
+ *
+ * @return The new comment that will be set for the tag.
+ */
+ public String getNewComment() {
+ return newComment;
+ }
+
+ /**
+ * Compare the UpdateTagComment instance with another object for equality. Two instances are
+ * considered equal if they designate the same new comment for the tag.
+ *
+ * @param o The object to compare with this instance.
+ * @return True if the object is equal to this instance, false otherwise.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ UpdateTagComment updateTagComment = (UpdateTagComment) o;
+ return newComment.equals(updateTagComment.newComment);
+ }
+
+ /**
+ * Generates a hash code for the UpdateTagComment instance.
+ *
+ * @return The hash code for the UpdateTagComment instance.
+ */
+ @Override
+ public int hashCode() {
+ return newComment.hashCode();
+ }
+
+ /**
+ * Get the string representation of the UpdateTagComment instance.
+ *
+ * @return The string representation of the UpdateTagComment instance.
+ */
+ @Override
+ public String toString() {
+ return "UPDATETAGCOMMENT " + newComment;
+ }
+ }
+
+ /** A tag change to set the property and value for the tag. */
+ final class SetProperty implements TagChange {
+ private final String property;
+ private final String value;
+
+ private SetProperty(String property, String value) {
+ this.property = property;
+ this.value = value;
+ }
+
+ /**
+ * Get the property name to set.
+ *
+ * @return The property name to set.
+ */
+ public String getProperty() {
+ return property;
+ }
+
+ /**
+ * Get the value to set the property to.
+ *
+ * @return The value to set the property to.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Compare the SetProperty instance with another object for equality. Two instances are
+ * considered equal if they designate the same property and value.
+ *
+ * @param o The object to compare with this instance.
+ * @return True if the object is equal to this instance, false otherwise.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ SetProperty setProperty = (SetProperty) o;
+ return property.equals(setProperty.property) && value.equals(setProperty.value);
+ }
+
+ /**
+ * Generates a hash code for the SetProperty instance.
+ *
+ * @return The hash code for the SetProperty instance.
+ */
+ @Override
+ public int hashCode() {
+ return property.hashCode() + value.hashCode();
+ }
+
+ /**
+ * Get the string representation of the SetProperty instance.
+ *
+ * @return The string representation of the SetProperty instance.
+ */
+ @Override
+ public String toString() {
+ return "SETTAGPROPERTY " + property + " = " + value;
+ }
+ }
+
+ /** A tag change to remove a property from the tag. */
+ final class RemoveProperty implements TagChange {
+ private final String property;
+
+ private RemoveProperty(String property) {
+ this.property = property;
+ }
+
+ /**
+ * Get the property name to remove.
+ *
+ * @return The property name to remove.
+ */
+ public String getProperty() {
+ return property;
+ }
+
+ /**
+ * Compare the RemoveProperty instance with another object for equality. Two instances are
+ * considered equal if they designate the same property to remove.
+ *
+ * @param o The object to compare with this instance.
+ * @return True if the object is equal to this instance, false otherwise.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ RemoveProperty removeProperty = (RemoveProperty) o;
+ return property.equals(removeProperty.property);
+ }
+
+ /**
+ * Generates a hash code for the RemoveProperty instance.
+ *
+ * @return The hash code for the RemoveProperty instance.
+ */
+ @Override
+ public int hashCode() {
+ return property.hashCode();
+ }
+
+ /**
+ * Get the string representation of the RemoveProperty instance.
+ *
+ * @return The string representation of the RemoveProperty instance.
+ */
+ @Override
+ public String toString() {
+ return "REMOVETAGPROPERTY " + property;
+ }
+ }
+}
diff --git a/api/src/main/java/com/datastrato/gravitino/tag/TagOperations.java b/api/src/main/java/com/datastrato/gravitino/tag/TagOperations.java
new file mode 100644
index 0000000000..4f4d3534d4
--- /dev/null
+++ b/api/src/main/java/com/datastrato/gravitino/tag/TagOperations.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.tag;
+
+import com.datastrato.gravitino.annotation.Evolving;
+import com.datastrato.gravitino.exceptions.NoSuchTagException;
+import com.datastrato.gravitino.exceptions.TagAlreadyExistsException;
+import java.util.Map;
+
+/**
+ * Interface for supporting global tag operations. This interface will provide tag listing, getting,
+ * creating, and other tag operations under a metalake. This interface will be mixed with
+ * GravitinoMetalake or GravitinoClient to provide tag operations.
+ */
+@Evolving
+public interface TagOperations {
+
+ /**
+ * List all the tag names under a metalake.
+ *
+ * @return The list of tag names.
+ */
+ String[] listTags();
+
+ /**
+ * List all the tags with detailed information under a metalake.
+ *
+ * @param extended If true, the extended information of the tag will be included.
+ * @return The list of tags.
+ */
+ Tag[] listTagsInfo(boolean extended);
+
+ /**
+ * Get a tag by its name under a metalake.
+ *
+ * @param name The name of the tag.
+ * @return The tag.
+ * @throws NoSuchTagException If the tag does not exist.
+ */
+ Tag getTag(String name) throws NoSuchTagException;
+
+ /**
+ * Create a tag under a metalake.
+ *
+ * @param name The name of the tag.
+ * @param comment The comment of the tag.
+ * @param properties The properties of the tag.
+ * @return The created tag.
+ * @throws TagAlreadyExistsException If the tag already exists.
+ */
+ Tag createTag(String name, String comment, Map<String, String> properties)
+ throws TagAlreadyExistsException;
+
+ /**
+ * Alter a tag under a metalake.
+ *
+ * @param name The name of the tag.
+ * @param changes The changes to apply to the tag.
+ * @return The altered tag.
+ * @throws NoSuchTagException If the tag does not exist.
+ * @throws IllegalArgumentException If the changes cannot be applied to the tag.
+ */
+ Tag alterTag(String name, TagChange... changes)
+ throws NoSuchTagException, IllegalArgumentException;
+
+ /**
+ * Delete a tag under a metalake.
+ *
+ * @param name The name of the tag.
+ * @return True if the tag is deleted, false if the tag does not exist.
+ */
+ boolean deleteTag(String name);
+}
diff --git a/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java b/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java
index 79f773b164..894d7df642 100644
--- a/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java
+++ b/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java
@@ -4,13 +4,7 @@
*/
package com.datastrato.gravitino.authorization;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.CATALOG;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.FILESET;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.METALAKE;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.SCHEMA;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.TABLE;
-import static com.datastrato.gravitino.authorization.SecurableObject.Type.TOPIC;
-
+import com.datastrato.gravitino.MetadataObject;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -22,23 +16,23 @@ public class TestSecurableObjects {
SecurableObject allMetalakes =
SecurableObjects.ofAllMetalakes(Lists.newArrayList(Privileges.CreateMetalake.allow()));
Assertions.assertEquals("*", allMetalakes.fullName());
- Assertions.assertEquals(METALAKE, allMetalakes.type());
+ Assertions.assertEquals(MetadataObject.Type.METALAKE, allMetalakes.type());
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- METALAKE,
+ MetadataObject.Type.METALAKE,
Lists.newArrayList("*"),
Lists.newArrayList(Privileges.UseMetalake.allow())));
SecurableObject metalake =
SecurableObjects.ofMetalake("metalake", Lists.newArrayList(Privileges.UseMetalake.allow()));
Assertions.assertEquals("metalake", metalake.fullName());
- Assertions.assertEquals(METALAKE, metalake.type());
+ Assertions.assertEquals(MetadataObject.Type.METALAKE, metalake.type());
SecurableObject anotherMetalake =
SecurableObjects.of(
- METALAKE,
+ MetadataObject.Type.METALAKE,
Lists.newArrayList("metalake"),
Lists.newArrayList(Privileges.UseMetalake.allow()));
Assertions.assertEquals(metalake, anotherMetalake);
@@ -46,10 +40,10 @@ public class TestSecurableObjects {
SecurableObject catalog =
SecurableObjects.ofCatalog("catalog", Lists.newArrayList(Privileges.UseCatalog.allow()));
Assertions.assertEquals("catalog", catalog.fullName());
- Assertions.assertEquals(CATALOG, catalog.type());
+ Assertions.assertEquals(MetadataObject.Type.CATALOG, catalog.type());
SecurableObject anotherCatalog =
SecurableObjects.of(
- CATALOG,
+ MetadataObject.Type.CATALOG,
Lists.newArrayList("catalog"),
Lists.newArrayList(Privileges.UseCatalog.allow()));
Assertions.assertEquals(catalog, anotherCatalog);
@@ -58,10 +52,10 @@ public class TestSecurableObjects {
SecurableObjects.ofSchema(
catalog, "schema", Lists.newArrayList(Privileges.UseSchema.allow()));
Assertions.assertEquals("catalog.schema", schema.fullName());
- Assertions.assertEquals(SCHEMA, schema.type());
+ Assertions.assertEquals(MetadataObject.Type.SCHEMA, schema.type());
SecurableObject anotherSchema =
SecurableObjects.of(
- SCHEMA,
+ MetadataObject.Type.SCHEMA,
Lists.newArrayList("catalog", "schema"),
Lists.newArrayList(Privileges.UseSchema.allow()));
Assertions.assertEquals(schema, anotherSchema);
@@ -69,10 +63,10 @@ public class TestSecurableObjects {
SecurableObject table =
SecurableObjects.ofTable(schema, "table", Lists.newArrayList(Privileges.ReadTable.allow()));
Assertions.assertEquals("catalog.schema.table", table.fullName());
- Assertions.assertEquals(TABLE, table.type());
+ Assertions.assertEquals(MetadataObject.Type.TABLE, table.type());
SecurableObject anotherTable =
SecurableObjects.of(
- TABLE,
+ MetadataObject.Type.TABLE,
Lists.newArrayList("catalog", "schema", "table"),
Lists.newArrayList(Privileges.ReadTable.allow()));
Assertions.assertEquals(table, anotherTable);
@@ -81,10 +75,10 @@ public class TestSecurableObjects {
SecurableObjects.ofFileset(
schema, "fileset", Lists.newArrayList(Privileges.UseSchema.allow()));
Assertions.assertEquals("catalog.schema.fileset", fileset.fullName());
- Assertions.assertEquals(FILESET, fileset.type());
+ Assertions.assertEquals(MetadataObject.Type.FILESET, fileset.type());
SecurableObject anotherFileset =
SecurableObjects.of(
- FILESET,
+ MetadataObject.Type.FILESET,
Lists.newArrayList("catalog", "schema", "fileset"),
Lists.newArrayList(Privileges.UseSchema.allow()));
Assertions.assertEquals(fileset, anotherFileset);
@@ -92,11 +86,11 @@ public class TestSecurableObjects {
SecurableObject topic =
SecurableObjects.ofTopic(schema, "topic", Lists.newArrayList(Privileges.ReadTopic.allow()));
Assertions.assertEquals("catalog.schema.topic", topic.fullName());
- Assertions.assertEquals(TOPIC, topic.type());
+ Assertions.assertEquals(MetadataObject.Type.TOPIC, topic.type());
SecurableObject anotherTopic =
SecurableObjects.of(
- TOPIC,
+ MetadataObject.Type.TOPIC,
Lists.newArrayList("catalog", "schema", "topic"),
Lists.newArrayList(Privileges.ReadTopic.allow()));
Assertions.assertEquals(topic, anotherTopic);
@@ -106,7 +100,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- METALAKE,
+ MetadataObject.Type.METALAKE,
Lists.newArrayList("metalake", "catalog"),
Lists.newArrayList(Privileges.UseCatalog.allow())));
Assertions.assertTrue(e.getMessage().contains("length of names is 2"));
@@ -115,7 +109,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- CATALOG,
+ MetadataObject.Type.CATALOG,
Lists.newArrayList("metalake", "catalog"),
Lists.newArrayList(Privileges.UseCatalog.allow())));
Assertions.assertTrue(e.getMessage().contains("length of names is 2"));
@@ -125,7 +119,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- TABLE,
+ MetadataObject.Type.TABLE,
Lists.newArrayList("metalake"),
Lists.newArrayList(Privileges.ReadTable.allow())));
Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
@@ -134,7 +128,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- TOPIC,
+ MetadataObject.Type.TOPIC,
Lists.newArrayList("metalake"),
Lists.newArrayList(Privileges.ReadTopic.allow())));
Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
@@ -143,7 +137,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- FILESET,
+ MetadataObject.Type.FILESET,
Lists.newArrayList("metalake"),
Lists.newArrayList(Privileges.ReadFileset.allow())));
Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
@@ -153,7 +147,7 @@ public class TestSecurableObjects {
IllegalArgumentException.class,
() ->
SecurableObjects.of(
- SCHEMA,
+ MetadataObject.Type.SCHEMA,
Lists.newArrayList("catalog", "schema", "table"),
Lists.newArrayList(Privileges.UseSchema.allow())));
Assertions.assertTrue(e.getMessage().contains("the length of names is 3"));