Skip to content

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

[#5131] Support tags in CLI (#5161)

Justin Mclean73c78632383e
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
index a7703b157c..12d869c429 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
@@ -33,6 +33,7 @@ public class CommandEntities {
public static final String COLUMN = "column";
public static final String USER = "user";
public static final String GROUP = "group";
+ public static final String TAG = "tag";
private static final HashSet<String> VALID_ENTITIES = new HashSet<>();
@@ -44,6 +45,7 @@ public class CommandEntities {
VALID_ENTITIES.add(COLUMN);
VALID_ENTITIES.add(USER);
VALID_ENTITIES.add(GROUP);
+ VALID_ENTITIES.add(TAG);
}
/**
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
index c3da72ce87..f599964c96 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
@@ -37,4 +37,10 @@ public class ErrorMessages {
public static final String USER_EXISTS = "User already exists.";
public static final String UNKNOWN_GROUP = "Unknown group.";
public static final String GROUP_EXISTS = "Group already exists.";
+ public static final String UNKNOWN_TAG = "Unknown tag.";
+ public static final String TAG_EXISTS = "Tag already exists.";
+ public static final String INVALID_SET_COMMAND =
+ "Unsupported combination of options either use --name or --property and --value.";
+ public static final String INVALID_REMOVE_COMMAND =
+ "Unsupported combination of options either use --name or --property.";
}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
index a56fdc2999..48b68bb445 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
@@ -129,4 +129,50 @@ public class FullName {
System.err.println(ErrorMessages.MISSING_NAME);
return null;
}
+
+ /**
+ * Helper method to determine a specific part of the full name exits.
+ *
+ * @param partNo The part of the name to obtain.
+ * @return True if the part exitsts.
+ */
+ public boolean hasNamePart(int partNo) {
+ /* Extract the name part from the full name if available. */
+ if (line.hasOption(GravitinoOptions.NAME)) {
+ String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\.");
+ int length = names.length;
+ int position = partNo;
+
+ return position <= length;
+ }
+
+ return false;
+ }
+
+ /**
+ * Does the catalog name exist?
+ *
+ * @return True if the catalog name exists, or false if it does not.
+ */
+ public boolean hasCatalogName() {
+ return hasNamePart(1);
+ }
+
+ /**
+ * Does the schema name exist?
+ *
+ * @return True if the schema name exists, or false if it does not.
+ */
+ public boolean hasSchemaName() {
+ return hasNamePart(2);
+ }
+
+ /**
+ * Does the table name exist?
+ *
+ * @return True if the table name exists, or false if it does not.
+ */
+ public boolean hasTableName() {
+ return hasNamePart(3);
+ }
}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
index d14ec4755a..7e95d59fc7 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
@@ -30,41 +30,53 @@ import org.apache.gravitino.cli.commands.CreateCatalog;
import org.apache.gravitino.cli.commands.CreateGroup;
import org.apache.gravitino.cli.commands.CreateMetalake;
import org.apache.gravitino.cli.commands.CreateSchema;
+import org.apache.gravitino.cli.commands.CreateTag;
import org.apache.gravitino.cli.commands.CreateUser;
import org.apache.gravitino.cli.commands.DeleteCatalog;
import org.apache.gravitino.cli.commands.DeleteGroup;
import org.apache.gravitino.cli.commands.DeleteMetalake;
import org.apache.gravitino.cli.commands.DeleteSchema;
import org.apache.gravitino.cli.commands.DeleteTable;
+import org.apache.gravitino.cli.commands.DeleteTag;
import org.apache.gravitino.cli.commands.DeleteUser;
import org.apache.gravitino.cli.commands.GroupDetails;
+import org.apache.gravitino.cli.commands.ListAllTags;
import org.apache.gravitino.cli.commands.ListCatalogProperties;
import org.apache.gravitino.cli.commands.ListCatalogs;
import org.apache.gravitino.cli.commands.ListColumns;
+import org.apache.gravitino.cli.commands.ListEntityTags;
import org.apache.gravitino.cli.commands.ListGroups;
import org.apache.gravitino.cli.commands.ListMetalakeProperties;
import org.apache.gravitino.cli.commands.ListMetalakes;
import org.apache.gravitino.cli.commands.ListSchema;
import org.apache.gravitino.cli.commands.ListSchemaProperties;
import org.apache.gravitino.cli.commands.ListTables;
+import org.apache.gravitino.cli.commands.ListTagProperties;
import org.apache.gravitino.cli.commands.ListUsers;
import org.apache.gravitino.cli.commands.MetalakeAudit;
import org.apache.gravitino.cli.commands.MetalakeDetails;
import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
import org.apache.gravitino.cli.commands.RemoveSchemaProperty;
+import org.apache.gravitino.cli.commands.RemoveTagProperty;
import org.apache.gravitino.cli.commands.SchemaAudit;
import org.apache.gravitino.cli.commands.SchemaDetails;
import org.apache.gravitino.cli.commands.ServerVersion;
import org.apache.gravitino.cli.commands.SetCatalogProperty;
import org.apache.gravitino.cli.commands.SetMetalakeProperty;
import org.apache.gravitino.cli.commands.SetSchemaProperty;
+import org.apache.gravitino.cli.commands.SetTagProperty;
import org.apache.gravitino.cli.commands.TableAudit;
import org.apache.gravitino.cli.commands.TableDetails;
+import org.apache.gravitino.cli.commands.TagDetails;
+import org.apache.gravitino.cli.commands.TagEntity;
+import org.apache.gravitino.cli.commands.UntagEntity;
import org.apache.gravitino.cli.commands.UpdateCatalogComment;
import org.apache.gravitino.cli.commands.UpdateCatalogName;
import org.apache.gravitino.cli.commands.UpdateMetalakeComment;
import org.apache.gravitino.cli.commands.UpdateMetalakeName;
+import org.apache.gravitino.cli.commands.UpdateTagComment;
+import org.apache.gravitino.cli.commands.UpdateTagName;
import org.apache.gravitino.cli.commands.UserDetails;
/* Gravitino Command line */
@@ -167,6 +179,8 @@ public class GravitinoCommandLine {
handleUserCommand();
} else if (entity.equals(CommandEntities.GROUP)) {
handleGroupCommand();
+ } else if (entity.equals(CommandEntities.TAG)) {
+ handleTagCommand();
}
}
@@ -367,6 +381,60 @@ public class GravitinoCommandLine {
}
}
+ /** Handles the command execution for Tags based on command type and the command line options. */
+ protected void handleTagCommand() {
+ String url = getUrl();
+ FullName name = new FullName(line);
+ String metalake = name.getMetalakeName();
+ String tag = line.getOptionValue(GravitinoOptions.TAG);
+
+ if (CommandActions.DETAILS.equals(command)) {
+ new TagDetails(url, ignore, metalake, tag).handle();
+ } else if (CommandActions.LIST.equals(command)) {
+ if (!name.hasCatalogName()) {
+ new ListAllTags(url, ignore, metalake).handle();
+ } else {
+ new ListEntityTags(url, ignore, metalake, name).handle();
+ }
+ } else if (CommandActions.CREATE.equals(command)) {
+ String comment = line.getOptionValue(GravitinoOptions.COMMENT);
+ new CreateTag(url, ignore, metalake, tag, comment).handle();
+ } else if (CommandActions.DELETE.equals(command)) {
+ new DeleteTag(url, ignore, metalake, tag).handle();
+ } else if (CommandActions.SET.equals(command)) {
+ String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+ String value = line.getOptionValue(GravitinoOptions.VALUE);
+
+ if (name == null && property != null && value != null) {
+ new SetTagProperty(url, ignore, metalake, tag, property, value).handle();
+ } else if (name != null && property == null && value == null) {
+ new TagEntity(url, ignore, metalake, name, tag).handle();
+ } else {
+ System.err.println(ErrorMessages.INVALID_SET_COMMAND);
+ }
+ } else if (CommandActions.REMOVE.equals(command)) {
+ String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+ if (property != null) {
+ new RemoveTagProperty(url, ignore, metalake, tag, property).handle();
+ } else if (name != null) {
+ new UntagEntity(url, ignore, metalake, name, tag).handle();
+ } else {
+ System.err.println(ErrorMessages.INVALID_REMOVE_COMMAND);
+ }
+ } else if (CommandActions.PROPERTIES.equals(command)) {
+ new ListTagProperties(url, ignore, metalake, tag).handle();
+ } else if (CommandActions.UPDATE.equals(command)) {
+ if (line.hasOption(GravitinoOptions.COMMENT)) {
+ String comment = line.getOptionValue(GravitinoOptions.COMMENT);
+ new UpdateTagComment(url, ignore, metalake, tag, comment).handle();
+ }
+ if (line.hasOption(GravitinoOptions.RENAME)) {
+ String newName = line.getOptionValue(GravitinoOptions.RENAME);
+ new UpdateTagName(url, ignore, metalake, tag, newName).handle();
+ }
+ }
+ }
+
/**
* Handles the command execution for Columns based on command type and the command line options.
*/
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
index d9ccbb4ad4..a9449743c3 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
@@ -39,6 +39,7 @@ public class GravitinoOptions {
public static final String PROPERTIES = "properties";
public static final String USER = "user";
public static final String GROUP = "group";
+ public static final String TAG = "tag";
public static final String AUDIT = "audit";
/**
@@ -55,9 +56,9 @@ public class GravitinoOptions {
options.addOption(createSimpleOption("s", SERVER, "Gravitino server version"));
options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)"));
options.addOption(createArgOption("n", NAME, "full entity name (dot separated)"));
- options.addOption(createArgOption("m", METALAKE, "Metalake name"));
- options.addOption(createSimpleOption("i", IGNORE, "Ignore client/sever version check"));
- options.addOption(createSimpleOption("a", AUDIT, "Display audit information"));
+ options.addOption(createArgOption("m", METALAKE, "metalake name"));
+ options.addOption(createSimpleOption("i", IGNORE, "ignore client/sever version check"));
+ options.addOption(createSimpleOption("a", AUDIT, "display audit information"));
// Create/update options
options.addOption(createArgOption("r", RENAME, "new entity name"));
@@ -66,9 +67,10 @@ public class GravitinoOptions {
options.addOption(createArgOption("V", VALUE, "property value"));
options.addOption(
createArgOption(
- "t", PROVIDER, "provider one of hadoop, hive, mysql, postgres, iceberg, kafka"));
+ "z", PROVIDER, "provider one of hadoop, hive, mysql, postgres, iceberg, kafka"));
options.addOption(createArgOption("l", USER, "user name"));
options.addOption(createArgOption("g", GROUP, "group name"));
+ options.addOption(createArgOption("t", TAG, "tag name"));
// Properties option can have multiple values
Option properties =
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
new file mode 100644
index 0000000000..76f6f85b48
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
@@ -0,0 +1,68 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.TagAlreadyExistsException;
+
+public class CreateTag extends Command {
+ protected final String metalake;
+ protected final String tag;
+ protected final String comment;
+
+ /**
+ * Create a new tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ * @param comment The comment of the tag.
+ */
+ public CreateTag(
+ String url, boolean ignoreVersions, String metalake, String tag, String comment) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ this.comment = comment;
+ }
+
+ /** Create a new tag. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ client.createTag(tag, comment, null);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (TagAlreadyExistsException err) {
+ System.err.println(ErrorMessages.TAG_EXISTS);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(tag + " created");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
new file mode 100644
index 0000000000..83211eb212
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
@@ -0,0 +1,71 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+
+public class DeleteTag extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+
+ /**
+ * Delete a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ */
+ public DeleteTag(String url, boolean ignoreVersions, String metalake, String tag) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ }
+
+ /** Delete a catalog. */
+ @Override
+ public void handle() {
+ boolean deleted = false;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ deleted = client.deleteTag(tag);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ if (deleted) {
+ System.out.println(tag + " deleted.");
+ } else {
+ System.out.println(tag + " not deleted.");
+ }
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
index ae43866a13..c5ffe69e83 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
@@ -30,7 +30,7 @@ public class DeleteUser extends Command {
protected final String user;
/**
- * Deletes a user.
+ * Delete a user.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java
new file mode 100644
index 0000000000..83e97b7ac0
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java
@@ -0,0 +1,62 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+
+/* Lists all tags in a metalake. */
+public class ListAllTags extends Command {
+
+ protected final String metalake;
+
+ /**
+ * Lists all tags in a metalake.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ */
+ public ListAllTags(String url, boolean ignoreVersions, String metalake) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ }
+
+ /** Lists all tags in a metalake. */
+ @Override
+ public void handle() {
+ String[] tags = new String[0];
+ try {
+ GravitinoClient client = buildClient(metalake);
+ tags = client.listTags();
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", tags);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
new file mode 100644
index 0000000000..9defeee8b9
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
@@ -0,0 +1,103 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.cli.FullName;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.rel.Table;
+
+/* Lists all tags in a metalake. */
+public class ListEntityTags extends Command {
+
+ protected String metalake;
+ protected FullName name;
+
+ /**
+ * Lists all tags in a metalake.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param name The name of the entity.
+ */
+ public ListEntityTags(String url, boolean ignoreVersions, String metalake, FullName name) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.name = name;
+ }
+
+ /** Lists all tags in a metalake. */
+ @Override
+ public void handle() {
+ String[] tags = new String[0];
+ try {
+ GravitinoClient client = buildClient(metalake);
+
+ // TODO fileset and topic
+ if (name.hasTableName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ String table = name.getTableName();
+ Table gTable =
+ client
+ .loadCatalog(catalog)
+ .asTableCatalog()
+ .loadTable(NameIdentifier.of(schema, table));
+ tags = gTable.supportsTags().listTags();
+ } else if (name.hasSchemaName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema);
+ tags = gSchema.supportsTags().listTags();
+ } else if (name.hasCatalogName()) {
+ String catalog = name.getCatalogName();
+ Catalog gCatalog = client.loadCatalog(catalog);
+ tags = gCatalog.supportsTags().listTags();
+ }
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchCatalogException err) {
+ System.err.println(ErrorMessages.UNKNOWN_CATALOG);
+ return;
+ } catch (NoSuchSchemaException err) {
+ System.err.println(ErrorMessages.UNKNOWN_SCHEMA);
+ return;
+ } catch (NoSuchTableException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TABLE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", tags);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
new file mode 100644
index 0000000000..14ea1d0660
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
@@ -0,0 +1,70 @@
+/*
+ * 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.cli.commands;
+
+import java.util.Map;
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+import org.apache.gravitino.tag.Tag;
+
+/** List the properties of a tag. */
+public class ListTagProperties extends ListProperties {
+
+ protected final String metalake;
+ protected final String tag;
+
+ /**
+ * List the properties of a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ */
+ public ListTagProperties(String url, boolean ignoreVersions, String metalake, String tag) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ }
+
+ /** List the properties of a tag. */
+ @Override
+ public void handle() {
+ Tag gTag = null;
+ try {
+ GravitinoClient client = buildClient(metalake);
+ gTag = client.getTag(tag);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ Map<String, String> properties = gTag.properties();
+ printProperties(properties);
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java
new file mode 100644
index 0000000000..fc94f3bc1c
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java
@@ -0,0 +1,72 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+import org.apache.gravitino.tag.TagChange;
+
+/** Remove a property of a tag. */
+public class RemoveTagProperty extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+ protected final String property;
+
+ /**
+ * Remove a property of a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ * @param property The name of the property.
+ */
+ public RemoveTagProperty(
+ String url, boolean ignoreVersions, String metalake, String tag, String property) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ this.property = property;
+ }
+
+ /** Remove a property of a catalog. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ TagChange change = TagChange.removeProperty(property);
+ client.alterTag(tag, change);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(property + " property removed.");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java
new file mode 100644
index 0000000000..5b0a73d3b6
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java
@@ -0,0 +1,80 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+import org.apache.gravitino.tag.TagChange;
+
+/** Set a property of a tag. */
+public class SetTagProperty extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+ protected final String property;
+ protected final String value;
+
+ /**
+ * Set a property of a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ * @param property The name of the property.
+ * @param value The value of the property.
+ */
+ public SetTagProperty(
+ String url,
+ boolean ignoreVersions,
+ String metalake,
+ String tag,
+ String property,
+ String value) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ this.property = property;
+ this.value = value;
+ }
+
+ /** Set a property of a tag. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ TagChange change = TagChange.setProperty(property, value);
+ client.alterTag(tag, change);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(tag + " property set.");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java
new file mode 100644
index 0000000000..711d330493
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java
@@ -0,0 +1,70 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.tag.Tag;
+
+public class TagDetails extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+
+ /**
+ * Displays the name and comment of a catalog.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ */
+ public TagDetails(String url, boolean ignoreVersions, String metalake, String tag) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ }
+
+ /** Displays the name and details of a specified tag. */
+ @Override
+ public void handle() {
+ Tag result = null;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ result = client.getTag(tag);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchCatalogException err) {
+ System.err.println(ErrorMessages.UNKNOWN_CATALOG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ if (result != null) {
+ System.out.println(result.name() + "," + result.comment());
+ }
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
new file mode 100644
index 0000000000..08e1d2ca1f
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
@@ -0,0 +1,109 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.cli.FullName;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.rel.Table;
+
+public class TagEntity extends Command {
+ protected final String metalake;
+ protected final FullName name;
+ protected final String tag;
+
+ /**
+ * Tag an entity with an existing tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param name The name of the entity.
+ * @param tag The name of the tag.
+ */
+ public TagEntity(String url, boolean ignoreVersions, String metalake, FullName name, String tag) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.name = name;
+ this.tag = tag;
+ }
+
+ /** Create a new tag. */
+ @Override
+ public void handle() {
+ String entity = "unknown";
+ String[] tags = new String[0];
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+
+ // TODO fileset and topic
+ if (name.hasTableName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ String table = name.getTableName();
+ Table gTable =
+ client
+ .loadCatalog(catalog)
+ .asTableCatalog()
+ .loadTable(NameIdentifier.of(schema, table));
+ tags = gTable.supportsTags().associateTags(new String[] {tag}, null);
+ entity = table;
+ } else if (name.hasSchemaName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema);
+ tags = gSchema.supportsTags().associateTags(new String[] {tag}, null);
+ entity = schema;
+ } else if (name.hasCatalogName()) {
+ String catalog = name.getCatalogName();
+ Catalog gCatalog = client.loadCatalog(catalog);
+ tags = gCatalog.supportsTags().associateTags(new String[] {tag}, null);
+ entity = catalog;
+ }
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchCatalogException err) {
+ System.err.println(ErrorMessages.UNKNOWN_CATALOG);
+ return;
+ } catch (NoSuchSchemaException err) {
+ System.err.println(ErrorMessages.UNKNOWN_SCHEMA);
+ return;
+ } catch (NoSuchTableException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TABLE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", tags);
+
+ System.out.println(entity + " tagged with " + all);
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
new file mode 100644
index 0000000000..91b9fcb157
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
@@ -0,0 +1,114 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.cli.FullName;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.rel.Table;
+
+public class UntagEntity extends Command {
+ protected final String metalake;
+ protected final FullName name;
+ protected final String tag;
+
+ /**
+ * Untag an entity with an existing tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param name The name of the entity.
+ * @param tag The name of the tag.
+ */
+ public UntagEntity(
+ String url, boolean ignoreVersions, String metalake, FullName name, String tag) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.name = name;
+ this.tag = tag;
+ }
+
+ /** Create a new tag. */
+ @Override
+ public void handle() {
+ String entity = "unknown";
+ String[] tags = new String[0];
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+
+ // TODO fileset and topic
+ if (name.hasTableName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ String table = name.getTableName();
+ Table gTable =
+ client
+ .loadCatalog(catalog)
+ .asTableCatalog()
+ .loadTable(NameIdentifier.of(schema, table));
+ tags = gTable.supportsTags().associateTags(null, new String[] {tag});
+ entity = table;
+ } else if (name.hasSchemaName()) {
+ String catalog = name.getCatalogName();
+ String schema = name.getSchemaName();
+ Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema);
+ tags = gSchema.supportsTags().associateTags(null, new String[] {tag});
+ entity = schema;
+ } else if (name.hasCatalogName()) {
+ String catalog = name.getCatalogName();
+ Catalog gCatalog = client.loadCatalog(catalog);
+ tags = gCatalog.supportsTags().associateTags(null, new String[] {tag});
+ entity = catalog;
+ }
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchCatalogException err) {
+ System.err.println(ErrorMessages.UNKNOWN_CATALOG);
+ return;
+ } catch (NoSuchSchemaException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TABLE);
+ return;
+ } catch (NoSuchTableException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TABLE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", tags);
+
+ if (all.equals("")) {
+ all = "nothing";
+ }
+
+ System.out.println(entity + " removed tag " + tag + ", now tagged with " + all);
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java
index f314d0759c..e4339e2460 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.CatalogChange;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
/** Update the name of a catalog. */
@@ -58,6 +59,9 @@ public class UpdateCatalogName extends Command {
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
+ } catch (NoSuchCatalogException err) {
+ System.err.println(ErrorMessages.UNKNOWN_CATALOG);
+ return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java
new file mode 100644
index 0000000000..17ad6f7e3c
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java
@@ -0,0 +1,72 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+import org.apache.gravitino.tag.TagChange;
+
+/** Update the comment of a tag. */
+public class UpdateTagComment extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+ protected final String comment;
+
+ /**
+ * Update the comment of a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the metalake.
+ * @param tag The name of the tag.
+ * @param comment New metalake comment.
+ */
+ public UpdateTagComment(
+ String url, boolean ignoreVersions, String metalake, String tag, String comment) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ this.comment = comment;
+ }
+
+ /** Update the comment of a tag. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ TagChange change = TagChange.updateComment(comment);
+ client.alterTag(tag, change);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(tag + " comment changed.");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java
new file mode 100644
index 0000000000..890cd26cfc
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java
@@ -0,0 +1,72 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchTagException;
+import org.apache.gravitino.tag.TagChange;
+
+/** Update the name of a tag. */
+public class UpdateTagName extends Command {
+
+ protected final String metalake;
+ protected final String tag;
+ protected final String name;
+
+ /**
+ * Update the name of a tag.
+ *
+ * @param url The URL of the Gravitino server.
+ * @param ignoreVersions If true don't check the client/server versions match.
+ * @param metalake The name of the tag.
+ * @param tag The name of the catalog.
+ * @param name The new metalake name.
+ */
+ public UpdateTagName(
+ String url, boolean ignoreVersions, String metalake, String tag, String name) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.tag = tag;
+ this.name = name;
+ }
+
+ /** Update the name of a catalog. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ TagChange change = TagChange.rename(name);
+ client.alterTag(tag, change);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchTagException err) {
+ System.err.println(ErrorMessages.UNKNOWN_TAG);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(tag + " name changed.");
+ }
+}
diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
index 2ca43d0603..cd2a55e2a3 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
@@ -37,6 +37,7 @@ public class TestCommandEntities {
CommandEntities.isValidEntity(CommandEntities.SCHEMA), "SCHEMA should be a valid entity");
assertTrue(
CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity");
+ assertTrue(CommandEntities.isValidEntity(CommandEntities.TAG), "TAG should be a valid entity");
}
@Test
diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java
index 27108fd67e..05e78b4c8c 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java
@@ -20,8 +20,10 @@
package org.apache.gravitino.cli;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
@@ -89,4 +91,46 @@ public class TestFulllName {
String namePart = fullName.getNamePart(3);
assertNull(namePart);
}
+
+ @Test
+ public void hasPartNameMetalake() throws Exception {
+ String[] args = {"metalake", "details", "--metalake", "metalake"};
+ CommandLine commandLine = new DefaultParser().parse(options, args);
+ FullName fullName = new FullName(commandLine);
+ assertFalse(fullName.hasCatalogName());
+ assertFalse(fullName.hasSchemaName());
+ assertFalse(fullName.hasTableName());
+ }
+
+ @Test
+ public void hasPartNameCatalog() throws Exception {
+ String[] args = {"catalog", "details", "--metalake", "metalake", "--name", "catalog"};
+ CommandLine commandLine = new DefaultParser().parse(options, args);
+ FullName fullName = new FullName(commandLine);
+ assertTrue(fullName.hasCatalogName());
+ assertFalse(fullName.hasSchemaName());
+ assertFalse(fullName.hasTableName());
+ }
+
+ @Test
+ public void hasPartNameSchema() throws Exception {
+ String[] args = {"schema", "details", "--metalake", "metalake", "--name", "catalog.schema"};
+ CommandLine commandLine = new DefaultParser().parse(options, args);
+ FullName fullName = new FullName(commandLine);
+ assertTrue(fullName.hasCatalogName());
+ assertTrue(fullName.hasSchemaName());
+ assertFalse(fullName.hasTableName());
+ }
+
+ @Test
+ public void hasPartNameTable() throws Exception {
+ String[] args = {
+ "table", "details", "--metalake", "metalake", "--name", "catalog.schema.table"
+ };
+ CommandLine commandLine = new DefaultParser().parse(options, args);
+ FullName fullName = new FullName(commandLine);
+ assertTrue(fullName.hasCatalogName());
+ assertTrue(fullName.hasSchemaName());
+ assertTrue(fullName.hasTableName());
+ }
}
diff --git a/docs/cli.md b/docs/cli.md
index 663a9c6ec6..750ab03a23 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -29,23 +29,24 @@ The general structure for running commands with the Gravitino CLI is `gcli entit
```bash
usage: gcli [metalake|catalog|schema|table|column] [list|details|create|delete|update|set|remove|properties] [options]
Options
+ -a,--audit display audit information
-c,--comment <arg> entity comment
-g,--group <arg> group name
-h,--help command help information
- -i,--ignore Ignore client/sever version check
+ -i,--ignore ignore client/sever version check
-l,--user <arg> user name
- -a,--audit display audit information
- -m,--metalake <arg> Metalake name
+ -m,--metalake <arg> metalake name
-n,--name <arg> full entity name (dot separated)
-P,--property <arg> property name
-p,--properties <arg> property name/value pairs
-r,--rename <arg> new entity name
-s,--server Gravitino server version
- -t,--provider <arg> provider one of hadoop, hive, mysql, postgres,
- iceberg, kafka
+ -t,--tag <arg> tag name
-u,--url <arg> Gravitino URL (default: http://localhost:8090)
-v,--version Gravitino client version
-V,--value <arg> property value
+ -z,--provider <arg> provider one of hadoop, hive, mysql, postgres,
+ iceberg, kafka
```
## Commands
@@ -147,6 +148,16 @@ For commands that accept multiple properties they can be specified in a couple o
3. gcli --properties n1=v1 --properties n2=v2 --properties n3=v3
+### Setting properties and tags
+
+Different options are needed to add a tag and set a property of a tag with `gcli tag set`. To add a
+tag, specify the tag (via --tag) and the entity to tag (via --name). To set the property of a tag
+(via --tag) you need to specify the property (via --property) and value (via --value) you want to
+set.
+
+To delete a tag, again, you need to specify the tag and entity, to remove a tag's property you need
+to select the tag and property.
+
### Metalake commands
#### Show all metalakes
@@ -410,3 +421,77 @@ gcli group list --metalake metalake_demo
```bash
gcli group delete --metalake metalake_demo --group new_group
```
+
+### Tag commands
+
+#### Display a tag's details
+
+```bash
+gcli tag details --metalake metalake_demo --tag tagA
+```
+
+#### Create a tag
+
+```bash
+gcli tag create --metalake metalake_demo --tag tagA
+```
+
+#### List all tag
+
+```bash
+gcli tag list --metalake metalake_demo
+```
+
+#### Delete a tag
+
+```bash
+gcli tag delete --metalake metalake_demo --tag tagA
+```
+
+#### Add a tag to an entity
+
+```bash
+gcli tag set --metalake metalake_demo --name catalog_postgres.hr --tag tagA
+```
+
+#### Remove a tag from an entity
+
+```bash
+gcli tag remove --metalake metalake_demo --name catalog_postgres.hr --tag tagA
+```
+
+#### List all tags on an entity
+
+```bash
+gcli tag list --metalake metalake_demo --name catalog_postgres.hr
+```
+
+#### List the properties of a tag
+
+```bash
+gcli tag properties --metalake metalake_demo --tag tagA
+```
+
+#### Set a properties of a tag
+
+```bash
+gcli tag set --metalake metalake_demo --tag tagA --property test --value value
+```
+
+#### Delete a property of a tag
+
+```bash
+gcli tag remove --metalake metalake_demo --tag tagA --property test
+```
+
+#### Rename a tag
+
+```bash
+gcli tag update --metalake metalake_demo --tag tagA --rename newTag
+```
+
+#### Update a tag's comment
+
+```bash
+gcli tag update --metalake metalake_demo --tag tagA --comment "new comment"
+```