This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new d5aa571c8 [#5379] Add update commands for fileset in Gravitino CLI
(#5381)
d5aa571c8 is described below
commit d5aa571c831ac20058ec7529478a223ac9716928
Author: Justin Mclean <[email protected]>
AuthorDate: Fri Nov 29 15:12:25 2024 +1100
[#5379] Add update commands for fileset in Gravitino CLI (#5381)
### What changes were proposed in this pull request?
Add update commands for fileset in Gravitino CLI
### Why are the changes needed?
to continue to extend the Gravitino CLI.
Fix: #5379
### Does this PR introduce _any_ user-facing change?
No, but it adds more commands to the Gravitino CLI.
### How was this patch tested?
Compiled and tested locally.
---
.../apache/gravitino/cli/GravitinoCommandLine.java | 9 ++
.../org/apache/gravitino/cli/GravitinoOptions.java | 1 +
.../apache/gravitino/cli/TestableCommandLine.java | 24 ++++++
.../cli/commands/UpdateFilesetComment.java | 95 ++++++++++++++++++++++
.../gravitino/cli/commands/UpdateFilesetName.java | 94 +++++++++++++++++++++
.../apache/gravitino/cli/TestCommandEntities.java | 2 +
.../apache/gravitino/cli/TestFilesetCommands.java | 60 ++++++++++++++
docs/cli.md | 12 +++
8 files changed, 297 insertions(+)
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 3d7f9fb57..24fea15f2 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.java
index fa5ac5a52..863bc5d21 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 options
options.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.java
index 8f610679c..a653f66a8 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.java
new file mode 100644
index 000000000..36c5ed228
--- /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.java
new file mode 100644
index 000000000..11dd1c8c8
--- /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.java
index 5f60d3e7e..4790a63dc 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.java
index d7932bde8..5663c1d49 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.md
index 15693bfc6..09e48063c 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -653,3 +653,15 @@ gcli fileset details --name hadoop.schema.fileset
```bash
gcli 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
+```