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 9cd7674e7 [#5379] Add property commands for filesets in Gravitio CLI 
(#5382)
9cd7674e7 is described below

commit 9cd7674e7209f7b14d715d4cac4d3c7494ce29bf
Author: Justin Mclean <jus...@classsoftware.com>
AuthorDate: Fri Nov 29 19:38:35 2024 +1100

    [#5379] Add property commands for filesets in Gravitio CLI (#5382)
    
    ### What changes were proposed in this pull request?
    
    Added property command for filesets in the Gravitio CLI.
    
    ### Why are the changes needed?
    
    Expand coverage of Java API in Gravitino CLI.
    
    Fix: #5379
    
    ### Does this PR introduce _any_ user-facing change?
    
    No, but it adds extra command to the Gravitino CLI.
    
    ### How was this patch tested?
    
    Compiled and tested locally.
---
 .../apache/gravitino/cli/GravitinoCommandLine.java | 12 ++-
 .../apache/gravitino/cli/TestableCommandLine.java  | 31 +++++++
 .../cli/commands/ListFilesetProperties.java        | 88 +++++++++++++++++++
 .../cli/commands/RemoveFilesetProperty.java        | 94 +++++++++++++++++++++
 .../gravitino/cli/commands/SetFilesetProperty.java | 98 ++++++++++++++++++++++
 .../apache/gravitino/cli/TestFilesetCommands.java  | 90 ++++++++++++++++++++
 docs/cli.md                                        | 18 ++++
 7 files changed, 430 insertions(+), 1 deletion(-)

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 24fea15f2..7bb455ae4 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
@@ -523,7 +523,7 @@ public class GravitinoCommandLine extends 
TestableCommandLine {
   }
 
   /**
-   * Handles the command execution for Filesets based on command type and the 
command line options.
+   * Handles the command execution for filesets based on command type and the 
command line options.
    */
   private void handleFilesetCommand() {
     String url = getUrl();
@@ -546,6 +546,16 @@ 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.SET.equals(command)) {
+      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+      String value = line.getOptionValue(GravitinoOptions.VALUE);
+      newSetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, 
property, value)
+          .handle();
+    } else if (CommandActions.REMOVE.equals(command)) {
+      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+      newRemoveFilesetProperty(url, ignore, metalake, catalog, schema, 
fileset, property).handle();
+    } else if (CommandActions.PROPERTIES.equals(command)) {
+      newListFilesetProperties(url, ignore, metalake, catalog, schema, 
fileset).handle();
     } else if (CommandActions.UPDATE.equals(command)) {
       if (line.hasOption(GravitinoOptions.COMMENT)) {
         String comment = line.getOptionValue(GravitinoOptions.COMMENT);
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 a653f66a8..a5db451eb 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
@@ -52,6 +52,7 @@ 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.ListFilesetProperties;
 import org.apache.gravitino.cli.commands.ListFilesets;
 import org.apache.gravitino.cli.commands.ListGroups;
 import org.apache.gravitino.cli.commands.ListIndexes;
@@ -68,6 +69,7 @@ import org.apache.gravitino.cli.commands.MetalakeAudit;
 import org.apache.gravitino.cli.commands.MetalakeDetails;
 import org.apache.gravitino.cli.commands.OwnerDetails;
 import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
+import org.apache.gravitino.cli.commands.RemoveFilesetProperty;
 import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
 import org.apache.gravitino.cli.commands.RemoveRoleFromGroup;
 import org.apache.gravitino.cli.commands.RemoveRoleFromUser;
@@ -78,6 +80,7 @@ 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.SetFilesetProperty;
 import org.apache.gravitino.cli.commands.SetMetalakeProperty;
 import org.apache.gravitino.cli.commands.SetOwner;
 import org.apache.gravitino.cli.commands.SetSchemaProperty;
@@ -551,4 +554,32 @@ public class TestableCommandLine {
       String rename) {
     return new UpdateFilesetName(url, ignore, metalake, catalog, schema, 
fileset, rename);
   }
+
+  protected ListFilesetProperties newListFilesetProperties(
+      String url, boolean ignore, String metalake, String catalog, String 
schema, String fileset) {
+    return new ListFilesetProperties(url, ignore, metalake, catalog, schema, 
fileset);
+  }
+
+  protected SetFilesetProperty newSetFilesetProperty(
+      String url,
+      boolean ignore,
+      String metalake,
+      String catalog,
+      String schema,
+      String fileset,
+      String property,
+      String value) {
+    return new SetFilesetProperty(url, ignore, metalake, catalog, schema, 
fileset, property, value);
+  }
+
+  protected RemoveFilesetProperty newRemoveFilesetProperty(
+      String url,
+      boolean ignore,
+      String metalake,
+      String catalog,
+      String schema,
+      String fileset,
+      String property) {
+    return new RemoveFilesetProperty(url, ignore, metalake, catalog, schema, 
fileset, property);
+  }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java
new file mode 100644
index 000000000..517598834
--- /dev/null
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java
@@ -0,0 +1,88 @@
+/*
+ * 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.NameIdentifier;
+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.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.file.Fileset;
+
+/** List the properties of a fileset. */
+public class ListFilesetProperties extends ListProperties {
+
+  protected final String metalake;
+  protected final String catalog;
+  protected final String schema;
+  protected final String fileset;
+
+  /**
+   * List the properties 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 catalog The name of the catalog.
+   * @param schema The name of the schema.
+   * @param fileset The name of the fileset.
+   */
+  public ListFilesetProperties(
+      String url,
+      boolean ignoreVersions,
+      String metalake,
+      String catalog,
+      String schema,
+      String fileset) {
+    super(url, ignoreVersions);
+    this.metalake = metalake;
+    this.catalog = catalog;
+    this.schema = schema;
+    this.fileset = fileset;
+  }
+
+  /** List the properties of a catalog. */
+  @Override
+  public void handle() {
+    Fileset gFileset = null;
+    try {
+      NameIdentifier name = NameIdentifier.of(schema, fileset);
+      GravitinoClient client = buildClient(metalake);
+      gFileset = 
client.loadCatalog(catalog).asFilesetCatalog().loadFileset(name);
+    } 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 (Exception exp) {
+      System.err.println(exp.getMessage());
+      return;
+    }
+
+    Map<String, String> properties = gFileset.properties();
+    printProperties(properties);
+  }
+}
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveFilesetProperty.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveFilesetProperty.java
new file mode 100644
index 000000000..d32b19503
--- /dev/null
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveFilesetProperty.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;
+
+/** Remove a property of a fileset. */
+public class RemoveFilesetProperty extends Command {
+
+  protected final String metalake;
+  protected final String catalog;
+  protected final String schema;
+  protected final String fileset;
+  protected final String property;
+
+  /**
+   * Remove a property 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 property The name of the property.
+   */
+  public RemoveFilesetProperty(
+      String url,
+      boolean ignoreVersions,
+      String metalake,
+      String catalog,
+      String schema,
+      String fileset,
+      String property) {
+    super(url, ignoreVersions);
+    this.metalake = metalake;
+    this.catalog = catalog;
+    this.schema = schema;
+    this.fileset = fileset;
+    this.property = property;
+  }
+
+  /** Remove a property of a fileset. */
+  @Override
+  public void handle() {
+    try {
+      NameIdentifier name = NameIdentifier.of(schema, fileset);
+      GravitinoClient client = buildClient(metalake);
+      FilesetChange change = FilesetChange.removeProperty(property);
+      client.loadCatalog(catalog).asFilesetCatalog().alterFileset(name, 
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(property + " property removed.");
+  }
+}
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetFilesetProperty.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetFilesetProperty.java
new file mode 100644
index 000000000..052af660f
--- /dev/null
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetFilesetProperty.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+/** Set a property of a fileset. */
+public class SetFilesetProperty extends Command {
+
+  protected final String metalake;
+  protected final String catalog;
+  protected final String schema;
+  protected final String fileset;
+  protected final String property;
+  protected final String value;
+
+  /**
+   * Set a property of a schema.
+   *
+   * @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 property The name of the property.
+   * @param value The value of the property.
+   */
+  public SetFilesetProperty(
+      String url,
+      boolean ignoreVersions,
+      String metalake,
+      String catalog,
+      String schema,
+      String fileset,
+      String property,
+      String value) {
+    super(url, ignoreVersions);
+    this.metalake = metalake;
+    this.catalog = catalog;
+    this.schema = schema;
+    this.fileset = fileset;
+    this.property = property;
+    this.value = value;
+  }
+
+  /** Set a property of a fileset. */
+  @Override
+  public void handle() {
+    try {
+      NameIdentifier name = NameIdentifier.of(schema, fileset);
+      GravitinoClient client = buildClient(metalake);
+      FilesetChange change = FilesetChange.setProperty(property, value);
+      client.loadCatalog(catalog).asFilesetCatalog().alterFileset(name, 
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(schema + " property set.");
+  }
+}
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 5663c1d49..314e118c7 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
@@ -32,7 +32,10 @@ import org.apache.commons.cli.Options;
 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.ListFilesetProperties;
 import org.apache.gravitino.cli.commands.ListFilesets;
+import org.apache.gravitino.cli.commands.RemoveFilesetProperty;
+import org.apache.gravitino.cli.commands.SetFilesetProperty;
 import org.apache.gravitino.cli.commands.UpdateFilesetComment;
 import org.apache.gravitino.cli.commands.UpdateFilesetName;
 import org.junit.jupiter.api.BeforeEach;
@@ -232,4 +235,91 @@ class TestFilesetCommands {
     commandLine.handleCommandLine();
     verify(mockUpdateName).handle();
   }
+
+  @Test
+  void testListFilesetPropertiesCommand() {
+    ListFilesetProperties mockListProperties = 
mock(ListFilesetProperties.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");
+    GravitinoCommandLine commandLine =
+        spy(
+            new GravitinoCommandLine(
+                mockCommandLine, mockOptions, CommandEntities.FILESET, 
CommandActions.PROPERTIES));
+    doReturn(mockListProperties)
+        .when(commandLine)
+        .newListFilesetProperties(
+            GravitinoCommandLine.DEFAULT_URL,
+            false,
+            "metalake_demo",
+            "catalog",
+            "schema",
+            "fileset");
+    commandLine.handleCommandLine();
+    verify(mockListProperties).handle();
+  }
+
+  @Test
+  void testSetFilesetPropertyCommand() {
+    SetFilesetProperty mockSetProperties = mock(SetFilesetProperty.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.PROPERTY)).thenReturn(true);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.PROPERTY)).thenReturn("property");
+    when(mockCommandLine.hasOption(GravitinoOptions.VALUE)).thenReturn(true);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.VALUE)).thenReturn("value");
+    GravitinoCommandLine commandLine =
+        spy(
+            new GravitinoCommandLine(
+                mockCommandLine, mockOptions, CommandEntities.FILESET, 
CommandActions.SET));
+    doReturn(mockSetProperties)
+        .when(commandLine)
+        .newSetFilesetProperty(
+            GravitinoCommandLine.DEFAULT_URL,
+            false,
+            "metalake_demo",
+            "catalog",
+            "schema",
+            "fileset",
+            "property",
+            "value");
+    commandLine.handleCommandLine();
+    verify(mockSetProperties).handle();
+  }
+
+  @Test
+  void testRemoveFilesetPropertyCommand() {
+    RemoveFilesetProperty mockSetProperties = 
mock(RemoveFilesetProperty.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.PROPERTY)).thenReturn(true);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.PROPERTY)).thenReturn("property");
+    GravitinoCommandLine commandLine =
+        spy(
+            new GravitinoCommandLine(
+                mockCommandLine, mockOptions, CommandEntities.FILESET, 
CommandActions.REMOVE));
+    doReturn(mockSetProperties)
+        .when(commandLine)
+        .newRemoveFilesetProperty(
+            GravitinoCommandLine.DEFAULT_URL,
+            false,
+            "metalake_demo",
+            "catalog",
+            "schema",
+            "fileset",
+            "property");
+    commandLine.handleCommandLine();
+    verify(mockSetProperties).handle();
+  }
 }
diff --git a/docs/cli.md b/docs/cli.md
index 09e48063c..979922162 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -665,3 +665,21 @@ gcli fileset update --name hadoop.schema.fileset --comment 
new_comment
 ```bash
 gcli fileset update --name hadoop.schema.fileset --rename new_name
 ```
+
+#### Display a fileset's properties
+
+```bash
+gcli fileset properties --name hadoop.schema.fileset 
+```
+
+#### Set a fileset's property
+
+```bash
+gcli fileset set  --name hadoop.schema.fileset --property test --value value
+```
+
+#### Remove a fileset's property
+
+```bash
+gcli fileset remove --name hadoop.schema.fileset --property test
+```

Reply via email to