World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#5379] Add update commands for fileset in Gravitino CLI (#5381)
Justin Mcleand5aa571c831a
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.javaindex 3d7f9fb573..24fea15f21 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@@ -546,6 +546,15 @@ public class GravitinoCommandLine extends TestableCommandLine {} else if (CommandActions.DELETE.equals(command)) {boolean force = line.hasOption(GravitinoOptions.FORCE);newDeleteFileset(url, ignore, force, metalake, catalog, schema, fileset).handle();+ } else if (CommandActions.UPDATE.equals(command)) {+ if (line.hasOption(GravitinoOptions.COMMENT)) {+ String comment = line.getOptionValue(GravitinoOptions.COMMENT);+ newUpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment).handle();+ }+ if (line.hasOption(GravitinoOptions.RENAME)) {+ String newName = line.getOptionValue(GravitinoOptions.RENAME);+ newUpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, newName).handle();+ }}}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.javaindex fa5ac5a520..863bc5d21e 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@@ -68,6 +68,7 @@ public class GravitinoOptions {options.addOption(createSimpleOption("x", INDEX, "display index information"));options.addOption(createSimpleOption("d", DISTRIBUTION, "display distribution information"));options.addOption(createSimpleOption(null, PARTITION, "display partition information"));+ options.addOption(createSimpleOption("o", OWNER, "display entity owner"));// Create/update optionsoptions.addOption(createArgOption(null, RENAME, "new entity name"));diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.javaindex 8f610679c0..a653f66a82 100644--- a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java@@ -92,6 +92,8 @@ import org.apache.gravitino.cli.commands.TopicDetails;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.UpdateFilesetComment;+import org.apache.gravitino.cli.commands.UpdateFilesetName;import org.apache.gravitino.cli.commands.UpdateMetalakeComment;import org.apache.gravitino.cli.commands.UpdateMetalakeName;import org.apache.gravitino.cli.commands.UpdateTagComment;@@ -527,4 +529,26 @@ public class TestableCommandLine {String fileset) {return new DeleteFileset(url, ignore, force, metalake, catalog, schema, fileset);}++ protected UpdateFilesetComment newUpdateFilesetComment(+ String url,+ boolean ignore,+ String metalake,+ String catalog,+ String schema,+ String fileset,+ String comment) {+ return new UpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment);+ }++ protected UpdateFilesetName newUpdateFilesetName(+ String url,+ boolean ignore,+ String metalake,+ String catalog,+ String schema,+ String fileset,+ String rename) {+ return new UpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, rename);+ }}diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetComment.javanew file mode 100644index 0000000000..36c5ed2285--- /dev/null+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetComment.java@@ -0,0 +1,95 @@+/*+ * 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.NameIdentifier;+import org.apache.gravitino.cli.ErrorMessages;+import org.apache.gravitino.client.GravitinoClient;+import org.apache.gravitino.exceptions.NoSuchCatalogException;+import org.apache.gravitino.exceptions.NoSuchFilesetException;+import org.apache.gravitino.exceptions.NoSuchMetalakeException;+import org.apache.gravitino.exceptions.NoSuchSchemaException;+import org.apache.gravitino.file.FilesetChange;++/** Update the comment of a catalog. */+public class UpdateFilesetComment extends Command {++ protected final String metalake;+ protected final String catalog;+ protected final String schema;+ protected final String fileset;+ protected final String comment;++ /**+ * Update the comment of a fileset.+ *+ * @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 catalog The name of the catalog.+ * @param schema The name of the schema.+ * @param fileset The name of the fileset.+ * @param comment New metalake comment.+ */+ public UpdateFilesetComment(+ String url,+ boolean ignoreVersions,+ String metalake,+ String catalog,+ String schema,+ String fileset,+ String comment) {+ super(url, ignoreVersions);+ this.metalake = metalake;+ this.catalog = catalog;+ this.schema = schema;+ this.fileset = fileset;+ this.comment = comment;+ }++ /** Update the comment of a catalog. */+ @Override+ public void handle() {+ try {+ NameIdentifier filesetName = NameIdentifier.of(schema, fileset);+ GravitinoClient client = buildClient(metalake);+ FilesetChange change = FilesetChange.updateComment(comment);++ client.loadCatalog(catalog).asFilesetCatalog().alterFileset(filesetName, change);+ } 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 (NoSuchFilesetException err) {+ System.err.println(ErrorMessages.UNKNOWN_FILESET);+ return;+ } catch (Exception exp) {+ System.err.println(exp.getMessage());+ return;+ }++ System.out.println(fileset + " comment changed.");+ }+}diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetName.javanew file mode 100644index 0000000000..11dd1c8c86--- /dev/null+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateFilesetName.java@@ -0,0 +1,94 @@+/*+ * 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.NameIdentifier;+import org.apache.gravitino.cli.ErrorMessages;+import org.apache.gravitino.client.GravitinoClient;+import org.apache.gravitino.exceptions.NoSuchCatalogException;+import org.apache.gravitino.exceptions.NoSuchFilesetException;+import org.apache.gravitino.exceptions.NoSuchMetalakeException;+import org.apache.gravitino.exceptions.NoSuchSchemaException;+import org.apache.gravitino.file.FilesetChange;++/** Update the name of a fileset. */+public class UpdateFilesetName extends Command {++ protected final String metalake;+ protected final String catalog;+ protected final String schema;+ protected final String fileset;+ protected final String name;++ /**+ * Update the name of a fileset.+ *+ * @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 catalog The name of the catalog.+ * @param schema The name of the schema.+ * @param fileset The name of the fileset.+ * @param name The new metalake name.+ */+ public UpdateFilesetName(+ String url,+ boolean ignoreVersions,+ String metalake,+ String catalog,+ String schema,+ String fileset,+ String name) {+ super(url, ignoreVersions);+ this.metalake = metalake;+ this.catalog = catalog;+ this.schema = schema;+ this.fileset = fileset;+ this.name = name;+ }++ /** Update the name of a catalog. */+ @Override+ public void handle() {+ try {+ NameIdentifier filesetName = NameIdentifier.of(schema, fileset);+ GravitinoClient client = buildClient(metalake);+ FilesetChange change = FilesetChange.rename(name);+ client.loadCatalog(catalog).asFilesetCatalog().alterFileset(filesetName, change);+ } 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 (NoSuchFilesetException err) {+ System.err.println(ErrorMessages.UNKNOWN_FILESET);+ return;+ } catch (Exception exp) {+ System.err.println(exp.getMessage());+ return;+ }++ System.out.println(fileset + " 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.javaindex 5f60d3e7ec..4790a63dc2 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@@ -38,6 +38,8 @@ public class TestCommandEntities {assertTrue(CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity");assertTrue(CommandEntities.isValidEntity(CommandEntities.TAG), "TAG should be a valid entity");+ assertTrue(+ CommandEntities.isValidEntity(CommandEntities.TOPIC), "TOPIC should be a valid entity");assertTrue(CommandEntities.isValidEntity(CommandEntities.FILESET), "FILESET should be a valid entity");assertTrue(diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.javaindex d7932bde85..5663c1d49f 100644--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java@@ -33,6 +33,8 @@ import org.apache.gravitino.cli.commands.CreateFileset;import org.apache.gravitino.cli.commands.DeleteFileset;import org.apache.gravitino.cli.commands.FilesetDetails;import org.apache.gravitino.cli.commands.ListFilesets;+import org.apache.gravitino.cli.commands.UpdateFilesetComment;+import org.apache.gravitino.cli.commands.UpdateFilesetName;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;@@ -172,4 +174,62 @@ class TestFilesetCommands {commandLine.handleCommandLine();verify(mockDelete).handle();}++ @Test+ void testUpdateFilesetCommentCommand() {+ UpdateFilesetComment mockUpdateComment = mock(UpdateFilesetComment.class);+ when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");+ when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.NAME))+ .thenReturn("catalog.schema.fileset");+ when(mockCommandLine.hasOption(GravitinoOptions.COMMENT)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.COMMENT)).thenReturn("new_comment");++ GravitinoCommandLine commandLine =+ spy(+ new GravitinoCommandLine(+ mockCommandLine, mockOptions, CommandEntities.FILESET, CommandActions.UPDATE));+ doReturn(mockUpdateComment)+ .when(commandLine)+ .newUpdateFilesetComment(+ GravitinoCommandLine.DEFAULT_URL,+ false,+ "metalake_demo",+ "catalog",+ "schema",+ "fileset",+ "new_comment");+ commandLine.handleCommandLine();+ verify(mockUpdateComment).handle();+ }++ @Test+ void testUpdateFilesetNameCommand() {+ UpdateFilesetName mockUpdateName = mock(UpdateFilesetName.class);+ when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");+ when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.NAME))+ .thenReturn("catalog.schema.fileset");+ when(mockCommandLine.hasOption(GravitinoOptions.RENAME)).thenReturn(true);+ when(mockCommandLine.getOptionValue(GravitinoOptions.RENAME)).thenReturn("new_name");++ GravitinoCommandLine commandLine =+ spy(+ new GravitinoCommandLine(+ mockCommandLine, mockOptions, CommandEntities.FILESET, CommandActions.UPDATE));+ doReturn(mockUpdateName)+ .when(commandLine)+ .newUpdateFilesetName(+ GravitinoCommandLine.DEFAULT_URL,+ false,+ "metalake_demo",+ "catalog",+ "schema",+ "fileset",+ "new_name");+ commandLine.handleCommandLine();+ verify(mockUpdateName).handle();+ }}diff --git a/docs/cli.md b/docs/cli.mdindex 15693bfc6f..09e48063c4 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -653,3 +653,15 @@ gcli fileset details --name hadoop.schema.fileset```bashgcli fileset delete --name hadoop.schema.fileset```++#### Update a fileset's comment++```bash+gcli fileset update --name hadoop.schema.fileset --comment new_comment+```++#### Rename a fileset++```bash+gcli fileset update --name hadoop.schema.fileset --rename new_name+```