From 719ad347deb467d38e3c4c34e58b73dd5ce33981 Mon Sep 17 00:00:00 2001 From: jun Date: Wed, 6 Nov 2024 00:18:44 +0800 Subject: [PATCH 01/11] fix: tableDetails command get wrong NameIdentifier --- .../java/org/apache/gravitino/cli/commands/TableDetails.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2169ccaaa17..3f8dcfd2b51 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 void handle() { 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()); From f5ab07609f9b3937fa01a60036c15558dbd8fd45 Mon Sep 17 00:00:00 2001 From: jun Date: Wed, 6 Nov 2024 00:27:18 +0800 Subject: [PATCH 02/11] improvement: display index information for tables in the Gravitino CLI --- .../gravitino/cli/GravitinoCommandLine.java | 5 +- .../gravitino/cli/GravitinoOptions.java | 2 + .../gravitino/cli/commands/ListIndexes.java | 84 +++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java 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 7e95d59fc7c..fc4cc01e2a2 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 @@ -47,6 +47,7 @@ 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.ListIndexes; import org.apache.gravitino.cli.commands.ListMetalakes; import org.apache.gravitino.cli.commands.ListSchema; import org.apache.gravitino.cli.commands.ListSchemaProperties; @@ -100,7 +101,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. metlake, catalog, schema, table etc etc. + * @param entity The entity to apply the command to e.g. metlake, 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) { @@ -335,6 +336,8 @@ private void handleTableCommand() { 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 { new TableDetails(url, ignore, metalake, catalog, schema, table).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 a9449743c3c..3cc6641d5fb 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 @@ -41,6 +41,7 @@ public class GravitinoOptions { public static final String GROUP = "group"; public static final String TAG = "tag"; public static final String AUDIT = "audit"; + public static final String INDEX = "index"; /** * Builds and returns the CLI options for Gravitino. @@ -59,6 +60,7 @@ public Options options() { 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("d", INDEX, "Display index infromation")); // Create/update options options.addOption(createArgOption("r", RENAME, "new entity name")); 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 00000000000..c3493e7f7fe --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java @@ -0,0 +1,84 @@ +/* + * 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.ArrayList; +import java.util.List; +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 schenma. + * @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 the two-dimensional array fieldNames to a single comma-separated string + List flattenedFieldNames = new ArrayList<>(); + for (String[] fieldHierarchy : index.fieldNames()) { + // Join nested fields (e.g., "a.b.c") for each inner array + flattenedFieldNames.add(String.join(".", fieldHierarchy)); + } + + String fields = String.join(", ", flattenedFieldNames); + String indexTitle = index.name(); + + all.append(indexTitle).append(": ").append(fields).append(System.lineSeparator()); + } + + System.out.print(all); + } +} From 1103b25cdce9befaa0f972ee8e3ff7ffeb6e2197 Mon Sep 17 00:00:00 2001 From: jun Date: Wed, 6 Nov 2024 20:26:43 +0800 Subject: [PATCH 03/11] fix command action and output format(CSV) --- .../apache/gravitino/cli/commands/ListIndexes.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index c3493e7f7fe..91a4d336b2e 100644 --- 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 @@ -37,7 +37,7 @@ public class ListIndexes extends TableCommand { * @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 schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public ListIndexes( @@ -66,17 +66,17 @@ public void handle() { StringBuilder all = new StringBuilder(); for (Index index : indexes) { - // Flatten the two-dimensional array fieldNames to a single comma-separated string + // Flatten the two-dimensional array fieldNames to a single dot-separated string List flattenedFieldNames = new ArrayList<>(); for (String[] fieldHierarchy : index.fieldNames()) { // Join nested fields (e.g., "a.b.c") for each inner array flattenedFieldNames.add(String.join(".", fieldHierarchy)); } - String fields = String.join(", ", flattenedFieldNames); - String indexTitle = index.name(); - - all.append(indexTitle).append(": ").append(fields).append(System.lineSeparator()); + String indexName = index.name(); + for (String field : flattenedFieldNames) { + all.append(field).append(",").append(indexName).append(System.lineSeparator()); + } } System.out.print(all); From 462ba4002decc6c39701112006dc9bc01d604e5e Mon Sep 17 00:00:00 2001 From: jun Date: Thu, 7 Nov 2024 00:33:56 +0800 Subject: [PATCH 04/11] fix import order --- .../main/java/org/apache/gravitino/cli/GravitinoCommandLine.java | 1 + 1 file changed, 1 insertion(+) 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 fc4cc01e2a2..0f4c32b2008 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 @@ -48,6 +48,7 @@ import org.apache.gravitino.cli.commands.ListGroups; import org.apache.gravitino.cli.commands.ListMetalakeProperties; 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.ListSchema; import org.apache.gravitino.cli.commands.ListSchemaProperties; From 2cb2860f6a67cf0de3367d099abe772eec97f427 Mon Sep 17 00:00:00 2001 From: jun Date: Thu, 7 Nov 2024 00:51:13 +0800 Subject: [PATCH 05/11] Update user document --- clients/cli/README.md | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/clients/cli/README.md b/clients/cli/README.md index 38f5b03dd1c..811d2cba9eb 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -24,6 +24,7 @@ Apache Gravitino CLI is a command-line tool that interacts with the Gravitino se ## Table of Contents - [Installation](#installation) +- [Table Commands](#table-commands) - [Running Tests](#running-tests) - [Contributing](#contributing) - [License](#license) @@ -59,6 +60,75 @@ Before you can build and run this project, it is suggested you have the followin gcli --help ``` +## Table Commands + +The CLI supports the following operations for tables: + +### List Tables + +Lists all tables in a specified schema. + +```bash +gcli table list --metalake --name . +``` + +Example: +```bash +gcli table list --metalake metalake_demo --name catalog_mysql.db +``` + +### Show Table Details + +Shows detailed information about a specific table. + +```bash +gcli table details --metalake --name .. +``` + +Example: +```bash +gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties +``` + +### List Table Indexes + +Shows all indexes defined for a specific table. + +```bash +gcli table details --metalake --name .. --index +``` + +Example: +```bash +gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index +``` + +### Create Table + +Creates a new table. + +```bash +gcli table create --metalake --name .. +``` + +Example: +```bash +gcli table create --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties +``` + +### Delete Table + +Deletes a specified table. + +```bash +gcli table delete --metalake --name .. +``` + +Example: +```bash +gcli table delete --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties +``` + ## Running Tests This project includes a suite of unit tests to verify its functionality. From a6ff447b224e57fb384304118a408d0882bbfaaa Mon Sep 17 00:00:00 2001 From: jun Date: Thu, 7 Nov 2024 10:07:16 +0800 Subject: [PATCH 06/11] Revert "Update user document" This reverts commit 01456c7d9ea345647eff0cbe124ffbdca5cc1c34. --- clients/cli/README.md | 70 ------------------------------------------- 1 file changed, 70 deletions(-) diff --git a/clients/cli/README.md b/clients/cli/README.md index 811d2cba9eb..38f5b03dd1c 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -24,7 +24,6 @@ Apache Gravitino CLI is a command-line tool that interacts with the Gravitino se ## Table of Contents - [Installation](#installation) -- [Table Commands](#table-commands) - [Running Tests](#running-tests) - [Contributing](#contributing) - [License](#license) @@ -60,75 +59,6 @@ Before you can build and run this project, it is suggested you have the followin gcli --help ``` -## Table Commands - -The CLI supports the following operations for tables: - -### List Tables - -Lists all tables in a specified schema. - -```bash -gcli table list --metalake --name . -``` - -Example: -```bash -gcli table list --metalake metalake_demo --name catalog_mysql.db -``` - -### Show Table Details - -Shows detailed information about a specific table. - -```bash -gcli table details --metalake --name .. -``` - -Example: -```bash -gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties -``` - -### List Table Indexes - -Shows all indexes defined for a specific table. - -```bash -gcli table details --metalake --name .. --index -``` - -Example: -```bash -gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index -``` - -### Create Table - -Creates a new table. - -```bash -gcli table create --metalake --name .. -``` - -Example: -```bash -gcli table create --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties -``` - -### Delete Table - -Deletes a specified table. - -```bash -gcli table delete --metalake --name .. -``` - -Example: -```bash -gcli table delete --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties -``` - ## Running Tests This project includes a suite of unit tests to verify its functionality. From a836e040e632dc19f8158aaeb5ae639b11622bbd Mon Sep 17 00:00:00 2001 From: jun Date: Thu, 7 Nov 2024 10:10:36 +0800 Subject: [PATCH 07/11] Update dev document for show table index, correct case consistency --- docs/cli.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 750ab03a23b..e06b1531ba1 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -40,13 +40,14 @@ The general structure for running commands with the Gravitino CLI is `gcli entit -P,--property property name -p,--properties property name/value pairs -r,--rename new entity name - -s,--server Gravitino server version + -s,--server gravitino server version -t,--tag tag name - -u,--url Gravitino URL (default: http://localhost:8090) - -v,--version Gravitino client version + -u,--url gravitino URL (default: http://localhost:8090) + -v,--version gravitino client version -V,--value property value -z,--provider provider one of hadoop, hive, mysql, postgres, iceberg, kafka + -d,--index shows all indexes defined for a specific table ``` ## Commands @@ -364,6 +365,12 @@ gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments --audit ``` +### Show table indexex + +```bash +gcli column list --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index +``` + #### Delete a table ```bash From 677cb2cc0712c58b17ca40a91122b8f88fe55ec3 Mon Sep 17 00:00:00 2001 From: JUN Date: Fri, 8 Nov 2024 00:17:43 +0800 Subject: [PATCH 08/11] Update cli.md --- docs/cli.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index e06b1531ba1..02e50fa6672 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -356,7 +356,7 @@ gcli table list --metalake metalake_demo --name catalog_postgres.hr #### Show tables details ```bash -gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments +gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments ``` #### Show tables audit information @@ -368,7 +368,7 @@ gcli table details --metalake metalake_demo --name catalog_postgres.hr.departmen ### Show table indexex ```bash -gcli column list --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index +gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index ``` #### Delete a table From 01d2d72c3ccb5d658b51d93071038d9edf8f54b4 Mon Sep 17 00:00:00 2001 From: jun Date: Fri, 8 Nov 2024 13:26:12 +0800 Subject: [PATCH 09/11] remove unnecessary import --- .../main/java/org/apache/gravitino/cli/GravitinoCommandLine.java | 1 - 1 file changed, 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 0f4c32b2008..5933c181330 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 @@ -46,7 +46,6 @@ 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.ListIndexes; import org.apache.gravitino.cli.commands.ListMetalakeProperties; import org.apache.gravitino.cli.commands.ListMetalakes; From 4ad6d999c3edd3d7196c1f6ed8e4ce4c7afecef4 Mon Sep 17 00:00:00 2001 From: jun Date: Fri, 8 Nov 2024 16:24:36 +0800 Subject: [PATCH 10/11] fix typo, simply code --- .../gravitino/cli/commands/ListIndexes.java | 24 +++++++++---------- docs/cli.md | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) 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 index 91a4d336b2e..330574985ea 100644 --- 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 @@ -19,8 +19,7 @@ package org.apache.gravitino.cli.commands; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.rel.indexes.Index; @@ -66,17 +65,16 @@ public void handle() { StringBuilder all = new StringBuilder(); for (Index index : indexes) { - // Flatten the two-dimensional array fieldNames to a single dot-separated string - List flattenedFieldNames = new ArrayList<>(); - for (String[] fieldHierarchy : index.fieldNames()) { - // Join nested fields (e.g., "a.b.c") for each inner array - flattenedFieldNames.add(String.join(".", fieldHierarchy)); - } - - String indexName = index.name(); - for (String field : flattenedFieldNames) { - all.append(field).append(",").append(indexName).append(System.lineSeparator()); - } + // 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/docs/cli.md b/docs/cli.md index 02e50fa6672..abb47aa316f 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -365,7 +365,7 @@ gcli table details --metalake metalake_demo --name catalog_postgres.hr.departmen gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments --audit ``` -### Show table indexex +### Show table indexes ```bash gcli table details --metalake metalake_demo --name catalog_mysql.db.iceberg_namespace_properties --index From fc12daeb2ad337ebf88620eb0375cc24e98b6cf8 Mon Sep 17 00:00:00 2001 From: JUN Date: Thu, 14 Nov 2024 11:41:07 +0800 Subject: [PATCH 11/11] fix typo --- .../java/org/apache/gravitino/cli/GravitinoCommandLine.java | 2 +- 1 file changed, 1 insertion(+), 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 d90b6f93bd5..dc4690edfa0 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 @@ -109,7 +109,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. metlake, catalog, schema, table 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) {