Skip to content

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

[#5277] improvement(cli): display index information for tables in the Gravitino CLI (#5476)

JUN76f29c99c22f
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 bb4649a093..b113137bd5 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
@@ -50,6 +50,7 @@ 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.ListIndexes;
import org.apache.gravitino.cli.commands.ListMetalakeProperties;
import org.apache.gravitino.cli.commands.ListMetalakes;
import org.apache.gravitino.cli.commands.ListRoles;
@@ -109,7 +110,7 @@ public class GravitinoCommandLine {
*
* @param line Parsed command line object.
* @param options Available options for the CLI.
- * @param entity The entity to apply the command to e.g. metalake, catalog, schema, table etc etc.
+ * @param entity The entity to apply the command to e.g. metalake, catalog, schema, table etc.
* @param command The type of command to run i.e. list, details, update, delete, or create.
*/
public GravitinoCommandLine(CommandLine line, Options options, String entity, String command) {
@@ -350,6 +351,8 @@ public class GravitinoCommandLine {
if (CommandActions.DETAILS.equals(command)) {
if (line.hasOption(GravitinoOptions.AUDIT)) {
new TableAudit(url, ignore, metalake, catalog, schema, table).handle();
+ } else if (line.hasOption(GravitinoOptions.INDEX)) {
+ new ListIndexes(url, ignore, metalake, catalog, schema, table).handle();
} else if (line.hasOption(GravitinoOptions.DISTRIBUTION)) {
new TableDistribution(url, ignore, metalake, catalog, schema, table).handle();
} else {
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 5fd34c558b..ed0dc41a11 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
@@ -42,6 +42,7 @@ public class GravitinoOptions {
public static final String TAG = "tag";
public static final String ROLE = "role";
public static final String AUDIT = "audit";
+ public static final String INDEX = "index";
public static final String FORCE = "force";
public static final String DISTRIBUTION = "distribution";
@@ -62,6 +63,7 @@ public class GravitinoOptions {
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(createSimpleOption("x", INDEX, "Display index infromation"));
options.addOption(createSimpleOption("d", DISTRIBUTION, "Display distribution information"));
// Create/update options
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
new file mode 100644
index 0000000000..330574985e
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
@@ -0,0 +1,82 @@
+/*
+ * 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.Arrays;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.rel.indexes.Index;
+
+/** Displays the index of a table. */
+public class ListIndexes extends TableCommand {
+
+ protected final String schema;
+ protected final String table;
+
+ /**
+ * Displays the index of a table.
+ *
+ * @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 table The name of the table.
+ */
+ public ListIndexes(
+ String url,
+ boolean ignoreVersions,
+ String metalake,
+ String catalog,
+ String schema,
+ String table) {
+ super(url, ignoreVersions, metalake, catalog);
+ this.schema = schema;
+ this.table = table;
+ }
+
+ /** Displays the details of a table's index. */
+ public void handle() {
+ Index[] indexes;
+
+ try {
+ NameIdentifier name = NameIdentifier.of(schema, table);
+ indexes = tableCatalog().loadTable(name).index();
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ StringBuilder all = new StringBuilder();
+ for (Index index : indexes) {
+ // Flatten nested field names into dot-separated strings (e.g., "a.b.c")
+ Arrays.stream(index.fieldNames())
+ // Convert nested fields to a single string
+ .map(nestedFieldName -> String.join(".", nestedFieldName))
+ .forEach(
+ fieldName ->
+ all.append(fieldName)
+ .append(",")
+ .append(index.name())
+ .append(System.lineSeparator()));
+ }
+
+ System.out.print(all);
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java
index 2169ccaaa1..3f8dcfd2b5 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java
@@ -56,7 +56,7 @@ public class TableDetails extends TableCommand {
Table gTable = null;
try {
- NameIdentifier name = NameIdentifier.of(table);
+ NameIdentifier name = NameIdentifier.of(schema, table);
gTable = tableCatalog().loadTable(name);
} catch (Exception exp) {
System.err.println(exp.getMessage());
diff --git a/docs/cli.md b/docs/cli.md
index 54176a66a6..c08ec85c3d 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -365,7 +365,7 @@ gcli table list --name catalog_postgres.hr
#### Show tables details
```bash
-gcli column list --name catalog_postgres.hr.departments
+gcli table details --name catalog_postgres.hr.departments
```
#### Show tables audit information
@@ -375,9 +375,12 @@ gcli table details --name catalog_postgres.hr.departments --audit
```
#### Show tables distribution information
+### Show table indexes
+
```bash
-gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments --distribution
+gcli table details --name catalog_mysql.db.iceberg_namespace_properties --index
```
+
#### Delete a table
```bash